#C8220. Network Connectivity Check
Network Connectivity Check
Network Connectivity Check
You are given a network consisting of (n) nodes and (m) bidirectional connections between them. Each connection links two different nodes. Your task is to determine if the entire network is connected, i.e. whether every node is reachable from node 1.
A network is said to be connected if there is a path between any pair of nodes. In other words, starting from node 1, you must be able to reach all other nodes using the available connections.
Input Format: The first line contains two space-separated integers (n) and (m). Each of the next (m) lines contains two integers (u) and (v) representing an undirected connection between nodes (u) and (v).
Output Format: Print a single line with the string "YES" if the network is connected, and "NO" otherwise.
inputFormat
The input is read from standard input. The first line contains two integers \(n\) (the number of nodes) and \(m\) (the number of connections). The next \(m\) lines each contain two integers \(u\) and \(v\) describing a bidirectional connection between node \(u\) and node \(v\).
Constraints:
- \(1 \leq n \leq 10^5\) (although sample cases are small, efficient solutions are expected for larger inputs)
- \(0 \leq m \leq 10^5\)
- \(1 \leq u, v \leq n\) and \(u \neq v\)
outputFormat
Output a single line to standard output containing "YES" if the network is connected or "NO" otherwise.
## sample4 3
1 2
2 3
3 4
YES
</p>