#K15321. Mutual Followers Detection
Mutual Followers Detection
Mutual Followers Detection
In this problem, you are given a social network with (m) users and (n) follow relationships. Each relationship is given as a directed edge from user (a) to user (b). Two users (a) and (b) are mutual followers if there exists a follow relationship from (a) to (b) and from (b) to (a). Your task is to find all unique pairs of mutual followers. For each mutual pair, output the pair as two numbers (a) and (b) with (a < b). The output should be sorted in ascending order first by the first element then by the second element. If no mutual follower pairs exist, do not print any output.
inputFormat
The first line contains two integers (m) and (n), where (m) is the number of users and (n) is the number of follow relationships. Each of the following (n) lines contains two integers (a) and (b) representing that user (a) follows user (b).
outputFormat
For each unique mutual follower pair ((a, b)) with (a < b), output a line with the two integers separated by a space. The pairs should be printed in ascending order. If no mutual follower pairs exist, print nothing.## sample
5 6
1 2
2 1
2 3
3 2
4 1
1 4
1 2
1 4
2 3
</p>