#P1960. 郁闷的记者

郁闷的记者

Description

You are a reporter for a sports newspaper, and you have received a challenging task: there are NN football teams participating in a tournament. You are given some match results and need to output the ranking of all teams from 11 to NN.

The following information applies:

  1. There are no draws.
  2. Different teams cannot share the same rank.
  3. For all 1a<bN1 \le a < b \le N, the team in position aa must be able to defeat the team in position bb.

Given partial match results, output one valid ranking, and determine whether there exists another ranking that also satisfies the given results.

Input Format

The first line contains NN, the number of teams, numbered from 11 to NN.

The second line contains MM, the number of given matches.

Each of the next MM lines contains two integers XiX_i, YiY_i, meaning team XiX_i can defeat team YiY_i.

Output Format

Output N+1N+1 lines. The first NN lines describe the ranking of the teams: the ii-th line contains the team ranked ii-th. The (N+1)(N+1)-th line contains one integer; output 00 if there is no other ranking that satisfies the given results, or 11 if there is at least one other valid ranking.

3
2
2 1
2 3
2
1
3
1

Hint

Constraints

  • 30%30\% of the testdata satisfies: 1N71 \le N \le 7, 1M151 \le M \le 15.
  • 60%60\% of the testdata satisfies: 1N1001 \le N \le 100, 1M2×1031 \le M \le 2 \times 10^3.
  • 100%100\% of the testdata satisfies: 1N5×1031 \le N \le 5 \times 10^3, 1M1051 \le M \le 10^5.

This problem uses Special Judge.

  • If the last line is incorrect, the message will be Your decide is wrong!.
  • If multiple rankings are possible and your ranking is wrong, the message will be Wrong ranks!.
  • If the ranking is unique and your answer is wrong, the message will be In line X,Your ans is wrong:expected = X,found = Y.

Translated by ChatGPT 5