#K2776. Balloon Assignment in Ponyville
Balloon Assignment in Ponyville
Balloon Assignment in Ponyville
In Ponyville, each building must be assigned a balloon type such that no two adjacent buildings (i.e. buildings connected by a road) share the same type. Formally, if two buildings i and j are connected by a road, then they must satisfy the constraint $$color(i) \neq color(j)$$. You are given n buildings and m roads. The buildings are labeled from 1 to n, and you are allowed to use balloon types represented by positive integers starting from 1. Your task is to assign a balloon type to each building so that the above condition is met. If there exists a valid assignment, print "YES" followed by the balloon types for each building. If no valid assignment is possible, print "NO".
You may output any valid balloon assignment if there are multiple solutions.
inputFormat
The input is read from standard input and has the following format:
n m u1 v1 u2 v2 ... um vm
Here, the first line contains two integers n (the number of buildings) and m (the number of roads). Each of the next m lines contains two integers u and v, representing a bidirectional road connecting building u and building v.
outputFormat
If a valid balloon assignment exists, output "YES" on the first line, and on the second line output n space-separated integers indicating the balloon type for each building (from building 1 to building n). If no valid assignment exists, output "NO".
## sample3 3
1 2
2 3
3 1
YES
1 2 3
</p>