#abc291e. E - Find Permutation

E - Find Permutation

Score : 500500 points

问题描述

存在一个长度为 NN 的序列 A=(A1,,AN)A=(A_1,\ldots,A_N),它是 1,,N1,\ldots,N 的一个排列。

虽然你并不知道序列 AA,但你知道对于 MM 对整数 (Xi,Yi)(X_i,Y_i),有 AXi<AYiA_{X_i}<A_{Y_i} 成立。

能否唯一确定序列 AA?如果可以,请找出序列 AA

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

Problem Statement

There is a length-NN sequence A=(A1,,AN)A=(A_1,\ldots,A_N) that is a permutation of 1,,N1,\ldots,N.

While you do not know AA, you know that AXi<AYiA_{X_i}<A_{Y_i} for MM pairs of integers (Xi,Yi)(X_i,Y_i).

Can AA be uniquely determined? If it is possible, find AA.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1M2×1051 \leq M \leq 2\times 10^5
  • 1Xi,YiN1\leq X_i,Y_i \leq N
  • All values in the input are integers.
  • There is an AA consistent with the input.

Input

The input is given from Standard Input in the following format:

NN MM

X1X_1 Y1Y_1

\vdots

XMX_M YMY_M

Output

If AA can be uniquely determined, print Yes in the first line. Then, print A1,,ANA_1,\ldots,A_N in the second line, separated by spaces.

If AA cannot be uniquely determined, just print No.

Sample Input 1

3 2
3 1
2 3

Sample Output 1

Yes
3 1 2

We can uniquely determine that A=(3,1,2)A=(3,1,2).

Sample Input 2

3 2
3 1
3 2

Sample Output 2

No

Two sequences (2,3,1)(2,3,1) and (3,2,1)(3,2,1) can be AA.

Sample Input 3

4 6
1 2
1 2
2 3
2 3
3 4
3 4

Sample Output 3

Yes
1 2 3 4

update @ 2024/3/10 12:09:00