#C8861. Non-Punishable Road Connectivity
Non-Punishable Road Connectivity
Non-Punishable Road Connectivity
You are given n intersections and m potential roads. Each road connects two intersections u and v. However, due to regulations only roads connecting intersections of different types (i.e. one with an odd number and one with an even number) are non-punishable and can be used. In other words, a road is valid if and only if
\( u \bmod 2 \neq v \bmod 2 \)
Your task is to determine if it is possible to use these non-punishable roads to connect all intersections. The intersections are numbered from 1 to n.
If all intersections can be connected using only valid roads, print YES
; otherwise, print NO
.
inputFormat
The first line contains two space-separated integers, n and m, where n is the number of intersections and m is the number of potential roads. Each of the next m lines contains two space-separated integers u and v, representing a road between intersections u and v.
outputFormat
Output a single line with the answer: YES
if all intersections can be connected using only non-punishable roads, or NO
otherwise.
4 4
1 2
2 3
3 4
4 1
YES