Maria Lost In Islands
Time: 1 s
Memory: 500 MB
Memory: 500 MB
Hello, good to see you again. You may know Maria from the previous problem, “Maria and her number!”. Today she decided she wanted to visit some islands near her home, so as planned, she started her journey in the morning by boat. She reached the island in the afternoon, and she explored the whole island. This island consists of some islands, which are named 1 to n, and they are connected together by bridges.
Maria likes to take snaps wherever she goes, so she became so busy while taking snaps that she didn’t realise that the last boat that carried the tourist from the island to shore left without her.
Now she is alone on the island, and there is a tiger that loves to hunt at night. This tiger can’t swim, but the tiger lives on the Nth island, and Maria is on the first island. Now the only way to save herself is to disconnect a bridge so that the tiger can’t reach her, but she can’t disconnect more than one bridge.
But she is confused about which bridge she needs to disconnect.So she needs your help to tell her that if she disconnects any particular bridge, then the tiger can’t reach her. If so, then print “YES’’; otherwise, “NO”.
Maria likes to take snaps wherever she goes, so she became so busy while taking snaps that she didn’t realise that the last boat that carried the tourist from the island to shore left without her.
Now she is alone on the island, and there is a tiger that loves to hunt at night. This tiger can’t swim, but the tiger lives on the Nth island, and Maria is on the first island. Now the only way to save herself is to disconnect a bridge so that the tiger can’t reach her, but she can’t disconnect more than one bridge.
But she is confused about which bridge she needs to disconnect.So she needs your help to tell her that if she disconnects any particular bridge, then the tiger can’t reach her. If so, then print “YES’’; otherwise, “NO”.
Input
The first line consists n,m the number of islands and the number of bridges.
Then the next m line contains two integers i and j (i ≠ j), denoting a bridge connecting i and j islands.
Constraint
\(2 <= n <= 10^5\\
2 <= m <= 2*10^5\\
1<= i,j <= n\)
Output
Print YES if she can be saved otherwise NO.
Examples
| Input | Output |
|---|---|
|
5 5
1 3 1 4 2 3 2 4 4 5 |
YES
|
| Input | Output |
|---|---|
|
5 6
1 3 1 4 2 3 2 4 4 5 1 5 |
NO
|
Notes
In the first example if she disconnects the bridge between 4th and 5th island then the tiger can't reach her.In the second example there is no bridge that if she disconnects then she can be saved.