#C1794. Graph Connectivity

    ID: 45038 Type: Default 1000ms 256MiB

Graph Connectivity

Graph Connectivity

You are given an undirected graph with n nodes and m edges. The nodes are numbered from 1 to n. For each edge, you are given two integers u and v which indicate that there is an edge between node u and node v.

A graph is said to be connected if for any two distinct nodes i and j, there exists a path from i to j. In other words, the graph is connected if $$ |\{v \mid v \text{ is reachable from node } 1\}| = n. $$

Your task is to write a program that determines whether the given graph is connected. If it is connected, output YES; otherwise, output NO.

inputFormat

The first line of input contains two integers n and m (n ≥ 1, m ≥ 0) — the number of nodes and the number of edges respectively. The next m lines each contain two integers u and v (1 ≤ u, vn) describing an edge of the graph.

outputFormat

Output a single line containing either YES if the graph is connected or NO otherwise.

## sample
4 2
1 2
3 4
NO