No.583 Railway Club
タグ : / 解いたユーザー数 193
作問者 :
nmnmnmnmnmnmnm
/ テスター :
はむこ
Problem Statement
The members of the railway club are planning to ride all of the special trains on the yukicoder Line.
What is the yukicoder Line?
・It is a single line with no branches, running from west to east.
・There are $N$ stations, in the order Station $0$, Station $1$, Station $2$, ..., Station $N-1$ from west to east.
・The yukicoder Line has $M$ special trains.
・A special train can be ridden from Station $Sa$ to Station $Sb$ or from Station $Sb$ to Station $Sa$. ($0 \le Sa < Sb \le N-1$)
・It is not possible to get off a special train partway through its trip.
What is the railway club members' plan?
・The members of the railway club gather at any station of the yukicoder Line.
・Next, the members travel using only special trains, transferring at stations.
・The members are satisfied once they have ridden a special train one way in either direction, and they do not ride that special train more than one way.
・The members ride all of the special trains that exist on the yukicoder Line.
・Finally, the members disband at any station of the yukicoder Line.
Determine whether the railway club's plan can be achieved.
Input
$N$ $M$
$Sa_0$ $Sb_0$
$Sa_1$ $Sb_1$
$\vdots$
$Sa_{M-1}$ $Sb_{M-1}$
$N$ is the number of stations on the yukicoder Line. $N$ is a positive integer. $2 \le N \le 500$.
$M$ is the number of special trains on the yukicoder Line. $M$ is a positive integer. $1 \le M \le \frac{N \times (N-1)}{2}$.
$Sa_i$ and $Sb_i$ are the stations at which the $i$-th special train can be boarded. Both are integers. $0 \le Sa_i < Sb_i \le N-1$.
All pairs of $Sa_i$ and $Sb_i$ are distinct.
Output
Print "YES" if the plan can be achieved, and "NO" otherwise, on one line.
Print a newline at the end.
Sample
Sample 1
Input
5 2 0 4 3 4
Output
YES
The yukicoder Line has 5 stations and 2 special trains.
The 0th special train runs back and forth between Station 0 and Station 4.
The 1st special train runs back and forth between Station 3 and Station 4.
The members of the railway club first gather at Station 0.
Next, they travel to Station 4 on the 0th special train.
Next, they travel to Station 3 on the 1st special train.
Finally, the members disband at Station 3.
The members can achieve the plan.
It can also be achieved by gathering at Station 3 and disbanding at Station 0.
Note that the members should not gather at Station 4.
If they ride one of the special trains one way from Station 4, they will be satisfied and unable to turn back.
They then cannot ride the other special train.
Sample 2
Input
5 2 0 2 3 4
Output
NO
The yukicoder Line has 5 stations and 2 special trains.
The 0th special train runs back and forth between Station 0 and Station 2.
The 1st special train runs back and forth between Station 3 and Station 4.
There is no way for the members of the railway club to travel between Station 2 and Station 3 using special trains.
Therefore, they cannot ride all of the special trains.
The members cannot achieve the plan.
Sample 3
Input
10 11 0 1 0 9 6 9 0 2 1 2 1 6 2 3 0 4 3 4 6 7 4 5
Output
NO
It seems this is not possible.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。