#abc223d. D - Restricted Permutation

D - Restricted Permutation

Score : 400400 points

问题描述

在满足以下条件的序列 PP 中,找出字典序最小的序列。这些序列是对 (1,2,,N)(1, 2, \dots, N) 的排列。

  • 对于每个 i=1,,Mi = 1, \dots, M,在序列 PP 中,AiA_i 出现的位置早于 BiB_i

如果不存在这样的序列 PP,则输出 -1

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Among the sequences PP that are permutations of (1,2,,N)(1, 2, \dots, N) and satisfy the condition below, find the lexicographically smallest sequence.

  • For each i=1,,Mi = 1, \dots, M, AiA_i appears earlier than BiB_i in PP.

If there is no such PP, print -1.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1M2×1051 \leq M \leq 2 \times 10^5
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • AiBiA_i \neq B_i
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

Print the answer.

Sample Input 1

4 3
2 1
3 4
2 4

Sample Output 1

2 1 3 4

The following five permutations PP satisfy the condition: $(2, 1, 3, 4), (2, 3, 1, 4), (2, 3, 4, 1), (3, 2, 1, 4), (3, 2, 4, 1)$. The lexicographically smallest among them is (2,1,3,4)(2, 1, 3, 4).

Sample Input 2

2 3
1 2
1 2
2 1

Sample Output 2

-1

No permutations PP satisfy the condition.

update @ 2024/3/10 09:49:28

}