No.2202 贅沢てりたまチキン
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. Show the original
Problem Statement
Yukiko Railway has $N$ stations $($ station $1,$ station $2, \ldots,$ station $N )$ and $M$ pairs of $2$ tracks.
The $i$-th pair consists of 2 tracks laid so as to bidirectionally connect the surface level of station $A_i$ with the underground level of station $B_i$, and the underground level of station $A_i$ with the surface level of station $B_i$, where these are $2$ different stations.
Determine whether it is possible to travel back and forth between the surface level and the underground level of each station using only the tracks of the railway.
Input
$N\ M$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_M$ $B_M$
Constraints
- $ 1 \le N \le 2\times10^{5}$
- $ 0 \le M \le \min(2\times10^{5},\frac{N(N-1)}{2})$
- $ 1 \le A_i, B_i \le N$
- $ A_i \neq B_i$
- $\{A_i,B_i\} \neq \{A_j,B_j\}$ ($1 \leq i \neq j \leq M$)
- All inputs are integers.
Output
If it is possible to travel back and forth between the surface level and the underground level of each station using only the tracks of the railway, print Yes; otherwise, print No.
Print a newline at the end.
Sample
Sample 1
Input
4 4 1 2 2 3 3 4 4 2
Output
Yes
You can move from the surface to the underground of each station as follows. Considering the reverse direction, you can also move from the underground to the surface, so travel back and forth is possible.
Station $1$ surface → Station $2$ underground → Station $3$ surface → Station $4$ underground → Station $2$ surface → Station $1$ underground
Station $2$ surface → Station $3$ underground → Station $4$ surface → Station $2$ underground
Station $3$ surface → Station $4$ underground → Station $2$ surface → Station $3$ underground
Station $4$ surface → Station $2$ underground → Station $3$ surface → Station $4$ underground
Sample 2
Input
5 4 1 2 2 3 3 4 5 3
Output
No
For every station, it is impossible to travel back and forth between its surface level and its underground level.
Sample 3
Input
6 5 1 2 2 3 3 4 4 5 5 1
Output
No
At station $6$, it is impossible to travel back and forth between the surface level and the underground level.
As in this case, if there is even $1$ station where travel back and forth is impossible, print No.
Sample 4
Input
9 10 1 3 9 4 3 6 2 6 6 8 3 8 5 4 7 4 5 9 2 8
Output
Yes
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
H20