問題一覧 > 通常問題

No.1640 Easy Coloring

レベル : / AI推定難易度 : 1400 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 111
作問者 : harurun / テスター : platinum magsta
お気に入りにしたユーザー ProblemId : 6612 / 自分の提出
問題文最終更新日: 2026-10-31 19:18:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 308 (順位表) の他の問題:

Problem Statement

There are $N$ white balls, numbered $1,2,...,N$ respectively.

A-kun performs the following operation for $i=1,2,...,N$.

  • In the $i$-th operation, paint either ball $A_i$ or ball $B_i$ black.

Determine whether it is possible to paint all the balls black with the $N$ operations.

If it is possible to paint all the balls black, also find which ball should be chosen in each operation.

If there are multiple ways to choose, you may output any of them.

Constraints

  • $1≤N≤10^5$

  • $1≤A_i,B_i≤N$

  • All inputs are integers.

Apart from the above constraints, there are evil cases satisfying the following constraint. The results of the evil cases do not affect the status of the submission.

  • $1≤N≤3 \times 10^5$

Input

$N$
$A_1$ $B_1$
$\vdots$
$A_N$ $B_N$
  • Line $1$ contains $N$.

  • Line $i+1$ $(1≤i≤N)$ contains $A_i$ and $B_i$, separated by a space.

Output

  • If it is not possible to paint all the balls black, print No on $1$ line.

  • If it is possible to paint all the balls black, output as follows.

    • On line $1$, print Yes.

    • On line $i+1$ $(1≤i≤N)$, print whichever of $A_i$ and $B_i$ you chose.

Print a newline at the end.

Sample

Sample 1
Input
4
1 2
3 4
4 3
2 1
Output
Yes
1
3
4
2

Besides this way of choosing, there are others such as $(2,4,3,1)$.

Sample 2
Input
3
1 2
1 2
1 2
Output
No

No matter how you choose, ball $3$ cannot be painted.

Sample 3
Input
5
1 2
4 3
3 1
5 4
2 1
Output
Yes
1
4
3
5
2

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。