#K95217. Network Connectivity Checker
Network Connectivity Checker
Network Connectivity Checker
Given ( n ) computers and ( m ) bidirectional connections among them, determine whether the entire network is connected. In other words, there must exist a path between any two distinct computers. A network is said to be connected if ( |V_{visited}| = n ), where ( V_{visited} ) is the set of computers reachable from any starting computer.
Input consists of two integers ( n ) and ( m ) on the first line, followed by ( m ) lines each containing two integers ( u ) and ( v ) representing a connection between computer ( u ) and computer ( v ). Output YES
if the network is fully connected, and NO
otherwise.
inputFormat
The first line contains two space-separated integers ( n ) and ( m ), representing the number of computers and the number of connections respectively. Each of the next ( m ) lines contains two space-separated integers ( u ) and ( v ), indicating that there is a bidirectional connection between computer ( u ) and computer ( v ).
outputFormat
Output a single line containing YES
if all computers are connected (directly or indirectly), or NO
otherwise.## sample
4 3
1 2
2 3
2 4
YES