

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
個の頂点と 本の辺からなる、単純(自己ループおよび多重辺を含まない)かつ連結な無向グラフが与えられます。
について、 番目の辺は頂点 と頂点 を結ぶ無向辺です。
各頂点を白または黒で塗る方法であって、下記の つの条件をともに満たすものが存在するかを判定し、存在する場合はその一例を示してください。
- 個以上の頂点が黒で塗られている。
- すべての について、下記の条件が成り立つ。
- 頂点 と「黒で塗られた頂点のうち頂点 からの距離が最小であるもの」の距離がちょうど である。
ここで、頂点 と頂点 の距離は、 と を結ぶパスの辺の本数としてあり得る最小値として定義されます。
制約
- 与えられるグラフは単純かつ連結
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
問題文中の条件を満たすように各頂点を白または黒で塗る方法が存在しない場合は、No
を出力せよ。
存在する場合は、下記の形式の通り、 行目に Yes
と出力し、 行目に各頂点を塗る方法を表す文字列 を出力せよ。
ここで、 は長さ の文字列であり、 について の 文字目は、頂点 を黒で塗るとき 、白で塗るとき である。
Yes
答えが複数ある場合、どれを出力しても正解とみなされる。
入力例 1Copy
5 5 1 2 2 3 3 1 3 4 4 5 2 1 0 5 2
出力例 1Copy
Yes 10100
例えば、頂点 を黒に、頂点 を白に塗るという方法が、問題文中の条件を満たします。
実際、 について、頂点 と「黒で塗られた頂点のうち頂点 からの距離が最小であるもの」の距離を で表すと、
であり、特に、 が成り立ちます。
入力例 2Copy
5 5 1 2 2 3 3 1 3 4 4 5 5 1 1 2 1 3 1 4 1 5 1
出力例 2Copy
No
問題文中の条件を満たすように各頂点を白または黒で塗る方法が存在しないため、No
を出力します。
入力例 3Copy
1 0 0
出力例 3Copy
Yes 1
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 .
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.
Sample Input 1Copy
5 5 1 2 2 3 3 1 3 4 4 5 2 1 0 5 2
Sample Output 1Copy
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 2Copy
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 2Copy
No
There is no way to satisfy the conditions by painting each vertex black or white, so you should print No
.
Sample Input 3Copy
1 0 0
Sample Output 3Copy
Yes 1