TORONTO KIDS COMPUTER CLUB | Aurora Saturday 14:30 Python Practice 22.04.02.
20518
post-template-default,single,single-post,postid-20518,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Aurora Saturday 14:30 Python Practice 22.04.02.

07 Apr Aurora Saturday 14:30 Python Practice 22.04.02.

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


No Comments

Sorry, the comment form is closed at this time.