#Lutece0456. Find the Champion
Find the Champion
Migrated from Lutece 456 Find the Champion
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
We all know that in Mathematics, if and , then we can easily get , however, in actual contest, things may not turn out to be as easy as that!
For example, in the Allelujah Championship of Mathematics (ACM), there are three players left, the contest is a knock-out type. So they need more matches to determine the final champion!
From the previous practice results we know that gongbaoa always beats kennethsnow, and kennethsnow will get a win on elfness for sure. However, when gongbaoa meets elfness, since elfness is a beautiful girl, gongbaoa always loses to her for some strange reasons. This can lead to a serious problem: Everyone has the chance to win the Competition!
If you are still confused, there's an easier explanation: If in the first round kennethsnow beat elfness, he will lose to gongbaoa, and the latter will be the champion. If in the first round gongbaoa beat kennethsnow, he will lose to elfness, and elfness will be the winner, still, kennethsnow has a chance to win, as long as gongbaoa loses to elfness in the first round. We call those three guys "potential champions".
Now, if there are people competing in ACM, of course we need at most matches to ditermine the champion. And for each round, we randomly select two players to have a match, the winner will get to the next round. We have some information about those players, that is to say, we can know some of the match result for sure.
To simplify the problem, we set a special rule to determion the champion for each match:
- If we have the direct information of that match, then the champion is determined for sure.
- If we don't have the direct information, but we can find a path from to , that is to say, if can beat , and can beat ..., finally, there is a who can beat , then we say there is a path from to . So, if there exists a path from to , but not a path from to , then we set as the champion.
- In other cases, any one of them has the chance to win.
Your task is simple: given the match information we currently have, please determine the number of "potential champions"
Input
The first line of the input is (no more than ), which stands for the number of test cases you need to solve. Then data sets follow.
For each dataset, the first line contains two numbers and , which stands for the number of nodes and edges. (, ) Then lines follow, each line with numbers and , (, ) means that if meet in the match, then will win for sure.
Output
For each dataset, For each test case, first output Case #C:
, where is the number of test case, from to .Then print out a single number which is the number of "potential champions", for the next line you should output exact numbers which are the id of those people in sorted order, the numbers are seperated with a single space.
Samples
3
3 3
0 1
1 2
2 0
3 0
2 1
0 1
Case #1: 3
0 1 2
Case #2: 3
0 1 2
Case #3: 1
0
Note
- In the second case, since we have no information of those players, according to the rule above, all of them will be the champion, so the answer is .
- Don't ask me what does "Allelujah Championship of Mathematics" mean! I don't know either!
Resources
kennethsnow