18 Feb Aurora Wednesday 18:30 Python Practice 23.02.15.
Question:
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.
Input Specification:
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.
Output Specification:
For each set of input data, if any two rooms are connected to each other, output “Yes”, otherwise output “No”.
Sample Input 3 3 1 2 2 3 3 1 3 3 1 2 2 3 3 2 0 0 Sample Output Yes No
Sorry, the comment form is closed at this time.