#C5928. Reconfiguring the Village Communication Network
Reconfiguring the Village Communication Network
Reconfiguring the Village Communication Network
You are given a village represented as a network of n houses and m cables connecting pairs of houses. Each cable connects two different houses.
The village authorities wish to reconfigure the network so that every pair of houses can communicate either directly or indirectly. However, they cannot add new cables – they can only remove some of the existing connections. Fortunately, they are allowed to rearrange the removed cables arbitrarily between houses.
This means that if the total number of cables is at least \(n-1\), it is possible to reconfigure the network into a spanning tree (which guarantees connectivity), regardless of the initial layout. Note that if the network is already connected, then no operation is needed.
Task
Determine whether it is possible to reconfigure the village network so that all houses become connected.
inputFormat
The first line contains two integers n and m separated by a space, where \(n\) is the number of houses and \(m\) is the number of cables.
Each of the following \(m\) lines contains two space‐separated integers u and v indicating that there is a cable connecting house u and house v.
Note: Houses are numbered from 1 to \(n\).
outputFormat
Output a single line containing either YES
if it is possible to reconfigure the network such that every house is connected, or NO
otherwise.
5 6
1 2
2 3
3 4
4 5
1 3
1 4
YES