URAL 1198. Jobbery

1. 题目


1198. Jobbery

Time limit: 2.0 second
Memory limit: 64 MB
Hard times came for Martian senate. Even this pride of Martian democracy can not oppose the almighty jobbery. Let’s consider the procedure of typical decision making. A member of Martian senate, who needs a certain law, submits it to senate. To improve his chances that law is accepted, he makes a phone call to each of senate members on whom he has the goods in his safe. Then he kindly suggests to those senators to support the new law. Moreover, to avoid occasional rejection of this important law, he asks each of them to make the same procedure with their safes. And each of them having no choice makes a similar range of phone calls to those on whome, in turn, he has the goods. If every senator supports the new law the president has nothing to do but to approve it. Otherwise he can reject it and send back to senate for law improvements.
It is evident, that just elected president Honestman dislikes such situation. So he starts to struggle against the jobbery. And first of all he wants to put to jail the most dangerous senate members. And definitely, if senator is able to make even the harmful law approved, he is a dangerous one. So secret service of Martian president has already checked safes of each senate member, and found out on whom each of them has the goods. Martian president knows about your achievements in programming and he asks you personally for a help.


The first line of input contains single integer N — the number of senate members (1 ≤ N ≤ 2000). Each senate member is uniquely identified with a number from 1 to N. Each of subsequent N lines contains information about senate members. The i-th line contains list of senate members (given by numeric identifiers) on whome he has the goods. List is terminated by number 0.


Print the list of identifiers of all dangerous senate members in a single line. The numbers in the list must be present in increasing order. The list must be terminated by number 0.


input output
Problem Author: Nikita Rybak

2. 思路

题目大意是说一些参议员握有其他参议员的把柄,可以进行胁迫其他参议员,这种关系可以传递,如A有B的把柄,B有C的把柄,则A可以直接胁迫B,B可以直接胁迫C,A也可以通过B来胁迫C。求“most dangerous senate members”。题目对“dangerous”的判定标准描述的不是很清楚,其实是求是否有一组参议员,他们之间任意两人之间都存在胁迫关系。


3. 代码