#abc299e. [abc299_e]Nearest Black Vertex
[abc299_e]Nearest Black Vertex
Problem Statement
You are given a simple connected undirected graph with vertices and edges (a simple graph contains no self-loop and no multi-edges).
For , the -th edge connects vertex and vertex bidirectionally.
Determine whether there is a way to paint each vertex black or white to satisfy both of the following conditions, and show one such way if it exists.
- At least one vertex is painted black.
- For every , the following holds:
- the minimum distance between vertex and a vertex painted black is exactly .
Here, the distance between vertex and vertex is the minimum number of edges in a path connecting and .
Constraints
- $N-1 \\leq M \\leq \\min\\lbrace N(N-1)/2, 2000 \\rbrace$
- The given graph is simple and connected.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
If there is no way to paint each vertex black or white to satisfy the conditions, print No
.
Otherwise, print Yes
in the first line, and a string representing a coloring of the vertices in the second line, as shown below.
Here, is a string of length such that, for each , the -th character of is if vertex is painted black and if white.
Yes
If multiple solutions exist, you may print any of them.
Sample Input 1
5 5
1 2
2 3
3 1
3 4
4 5
2
1 0
5 2
Sample Output 1
Yes
10100
One way to satisfy the conditions is to paint vertices black and vertices white.
Indeed, for each , let denote the minimum distance between vertex and a vertex painted black, and we have , where .
Sample Input 2
5 5
1 2
2 3
3 1
3 4
4 5
5
1 1
2 1
3 1
4 1
5 1
Sample Output 2
No
There is no way to satisfy the conditions by painting each vertex black or white, so you should print No
.
Sample Input 3
1 0
0
Sample Output 3
Yes
1