07 Apr Aurora Saturday 14:30 Python Practice 22.04.02.
In order to train Jason’s sense of direction, Gordon built a big castle with N rooms (N<=10000) and M channels (M<=100000). Each channel is one-way, that is, if you say a certain channel connects from room A to room B. It only means that room A can reach room B through this channel, but it does not mean that room A can be reached from room B through it. Gordon needs to ask you to write a program to confirm whether any two rooms are connected to each other, that is: for any i and j, there is at least one channel from room i to room j, and there is also a channel from room j to Room i.
The input contains multiple test cases. Each case starts with a line has two numbers: N and M, and the next M lines have two numbers a and b in each line, indicating that a channel can go from room A to room B. The input ends with two zeros at the end.
For each set of input data, if any two rooms are connected to each other, output “Yes”, otherwise output “No”.