atcoder#ABC299E. [ABC299E] Nearest Black Vertex
[ABC299E] Nearest Black Vertex
Score : points
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 .
- 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
- 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.
5 5
1 2
2 3
3 1
3 4
4 5
2
1 0
5 2
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 .
5 5
1 2
2 3
3 1
3 4
4 5
5
1 1
2 1
3 1
4 1
5 1
No
There is no way to satisfy the conditions by painting each vertex black or white, so you should print No
.
1 0
0
Yes
1