~/algor $ cat problems/graf-daraxtmi
Is the graph a tree?
Easy
1000 ms
128 MB
30%
An undirected graph with $n$ vertices and $m$ edges is given. The vertices are numbered from $1$ to $n$. If the graph is a tree — that is, it is connected and has no cycles — print YES, otherwise print NO.
Input
The first line contains two integers: $n$ and $m$. Each of the next $m$ lines contains two positive integers: $u$ and $v$ — the vertices joined by an edge.
Output
YES or NO.
Note
$1 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le u, v \le n$
The graph may have multiple edges and loops.
Examples
Input #1
4 3 1 2 2 3 2 4
Output #1
YES
Input #2
4 3 1 2 2 3 3 1
Output #2
NO