Autobiography
시간 제한1초메모리 제한1024 MB
무방향 그래프에서 색이 b-o-b-o 순서가 되는 서로 다른 네 정점의 경로 순서쌍을 센다.
문제
Bobo has an undirected graph with vertices and edges. The vertices are numbered by , and the -th edge is between the -th and the -th vertex. Plus, the -th vertex is associated with a character .
Find the number of ways to choose four distinct vertices such that
- and , and , and are connected by an edge,
- , , , .
입력
The input consists of several test cases terminated by end-of-file. For each test case,
The first line contains two integers and .
The second line contains characters .
For the following lines, the -th line contains two integers and .
출력
For each test case, output an integer which denotes the number of ways.
제한
- for each
- for each
- for each
- for each
- In each input, the sum of does not exceed . The sum of does not exceed .
힌트
For the first test case, there are quadrangles , .
For the second test case, there are quadrangles , , , .
For the third test case, there are no valid quadrangles.