#P2244. Potential Debate Tournament Winners

    ID: 15522 Type: Default 1000ms 256MiB

Potential Debate Tournament Winners

Potential Debate Tournament Winners

The debate round in an election works as follows: as long as more than \(2\) candidates remain, two are selected to debate. The loser is eliminated and the winner stays in the competition until only one candidate remains, who is declared the winner.

The historian Geheimnis has collected information on all \(n\) candidates and found that if two candidates have ever competed before, their match outcome in any future encounter is predetermined (i.e. fixed according to history). With these constraints, your task is to determine which candidates may possibly win the debate tournament.

Input details: The first line contains two integers \(n\) and \(m\), where \(n\) is the number of candidates and \(m\) is the number of historical forced results. Each of the following \(m\) lines contains two integers \(u\) and \(v\) indicating that in any debate between candidate \(u\) and candidate \(v\), candidate \(u\) will always win.

Output details: Print, in increasing order, the indices of all candidates who can potentially become the tournament champion by scheduling debates arbitrarily such that they never directly face an opponent who is predetermined to beat them. In matches between candidates with no historical result, the outcome can be chosen in favor of any candidate.

Hint: It can be shown that a candidate can win if and only if it belongs to a strongly connected component in the forced outcome graph with no incoming edge from another component. (Use \(\LaTeX\) for formulas like \(2\)).

inputFormat

The first line contains two integers \(n\) (the number of candidates) and \(m\) (the number of historical match results). The following \(m\) lines each contain two integers \(u\) and \(v\) (1-indexed) indicating that candidate \(u\) is forced to win against candidate \(v\) if they debate.

outputFormat

Output a line with the indices of all candidates that could possibly win the tournament, in increasing order, separated by spaces.

sample

4 3
1 2
2 3
4 3
1 4

</p>