#C11312. Mutual Followers Count
Mutual Followers Count
Mutual Followers Count
You are given a social network with n users and m following relationships. A following relationship is represented by a pair of integers (u, v), meaning user u follows user v. Two users u and v are considered mutual followers if u follows v and v follows u.
Your task is to count the number of mutual following pairs in the network. Note that each mutual pair should be counted only once.
The relation can be mathematically formulated as follows: For users u and v, if $$ \text{if } u \in F(v) \text{ and } v \in F(u) $$ then the pair \((u,v)\) is mutual. Remember to count each pair only once.
Input/Output: The problem follows the standard input/output format. Read from stdin
and write to stdout
.
inputFormat
The input begins with an integer T representing the number of test cases.
For each test case, the first line contains two space-separated integers n and m, where n is the number of users (labeled from 1 to n) and m is the number of following relationships.
This is followed by m lines, each containing two space-separated integers u and v indicating that user u follows user v.
outputFormat
For each test case, output a single line with one integer: the number of mutual following pairs.
## sample2
3 3
1 2
2 1
1 3
4 3
1 2
2 3
3 1
1
0
</p>