#K91972. Water Supply Network

    ID: 38094 Type: Default 1000ms 256MiB

Water Supply Network

Water Supply Network

In many urban settings, it is crucial to ensure that water reaches every house in the city. In this problem, you are given an undirected graph represented by (N) houses and (M) bidirectional pipes connecting pairs of houses. Water is supplied from house numbered 1 (the reservoir). Your task is to determine if water can reach every house via the network of pipes.

Formally, given an undirected graph (G = (V, E)) with (|V|=N) and (|E|=M), check whether all vertices are reachable from vertex 1.

You can solve this problem using a graph traversal algorithm, such as Breadth-First Search (BFS) or Depth-First Search (DFS).

inputFormat

The first line of input contains two integers (N) and (M), where (1 \le N \le 10^5) represents the number of houses, and (M) represents the number of pipes connecting the houses. Each of the following (M) lines contains two integers (u) and (v), indicating that there is a bidirectional pipe connecting house (u) and house (v).

outputFormat

Output a single line containing either "YES" if all houses are reachable from house 1, or "NO" otherwise.## sample

5 4
1 2
1 3
3 4
4 5
YES