No.1640 Easy Coloring
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
Noon $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もしくは右上の雲マークをクリックしてアカウントを作成してください。
harurun
platinum
magsta