Category

Similar Problems

0746. Connection

Time limit : 1000 ms
Memory limit : 64 mb

In this task you need to check whether the given undirected graph is connected. That it is possible to go from any vertex to any other along the edges of this graph.

Input

 The first line of the input are given numbers N and M are separated by

spaces – the number of vertices in the graph, respectively (1 ≤ N ≤ 105

0 ≤ M ≤ 105). The following M lines contain two numbers ui and vi by a

space (1 ≤ uivi ≤ N); each such line means that the graph there is an edge between vertices ui and vi.

Output      

Bring out the "YES", if the graph is connected, and "NO" otherwise.

Samples                                  

Input

Output

1

3 2

1 2

3 2

YES

2

3 1

1 3

NO

 

 

Tayyorladi: Azat Yusupov
Text from: e-olimp.com