Tinkoff Challenge - Final Round (Codeforces Round 414, rated, Div. 1 + Div. 2)
D
Labelling Cities
Codeforces
2400
原题
← CE →
翻译中…

Oleg the bank client lives in Bankopolia. There are $*n*$ cities in Bankopolia and some pair of cities are connected directly by bi-directional roads. The cities are numbered from $1$ to $*n*$. There are a total of $*m*$ roads in Bankopolia, the $*i*$-th road connects cities $*u*_{*i*}$ and $*v*_{*i*}$. It is guaranteed that from each city it is possible to travel to any other city using some of the roads.

翻译中…

Oleg wants to give a label to each city. Suppose the label of city $*i*$ is equal to $*x*_{*i*}$. Then, it must hold that for all pairs of cities $(*u*, *v*)$ the condition $|*x*_{*u*} - *x*_{*v*}| ≤ 1$ holds if and only if there is a road connecting $*u*$ and $*v*$.

翻译中…

Oleg wonders if such a labeling is possible. Find an example of such labeling if the task is possible and state that it is impossible otherwise.

翻译中…

Input

翻译中…

The first line of input contains two space-separated integers $*n*$ and $*m*$ ($2 ≤ *n* ≤ 3·10^{5}$, $1 ≤ *m* ≤ 3·10^{5}$) — the number of cities and the number of roads.

翻译中…

Next, $*m*$ lines follow. The $*i*$-th line contains two space-separated integers $*u*_{*i*}$ and $*v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$, $*u*_{*i*} ≠ *v*_{*i*}$) — the cities connected by the $*i*$-th road. It is guaranteed that there is at most one road between each pair of cities and it is possible to travel from any city to any other city using some roads.

翻译中…

Output

翻译中…

If the required labeling is not possible, output a single line containing the string "NO" (without quotes).

翻译中…

Otherwise, output the string "YES" (without quotes) on the first line. On the next line, output $*n*$ space-separated integers, $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$. The condition $1 ≤ *x*_{*i*} ≤ 10^{9}$ must hold for all $*i*$, and for all pairs of cities $(*u*, *v*)$ the condition $|*x*_{*u*} - *x*_{*v*}| ≤ 1$ must hold if and only if there is a road connecting $*u*$ and $*v*$.

翻译中…

Note

翻译中…

For the first sample, $*x*_{1} = 2$, $*x*_{2} = 3$, $*x*_{3} = *x*_{4} = 1$ is a valid labeling. Indeed, $(3, 4)$, $(1, 2)$, $(1, 3)$, $(1, 4)$ are the only pairs of cities with difference of labels not greater than $1$, and these are precisely the roads of Bankopolia.

翻译中…

For the second sample, all pairs of cities have difference of labels not greater than $1$ and all pairs of cities have a road connecting them.

翻译中…

For the last sample, it is impossible to construct a labeling satisfying the given constraints.

翻译中…

样例

Input #1
4 4
1 2
1 3
1 4
3 4
Output #1
YES
2 3 1 1
InputCopy OutputCopy
Input #2
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
5 4
Output #2
YES
1 1 1 1 1
InputCopy OutputCopy
Input #3
4 3
1 2
1 3
1 4
Output #3
NO
InputCopy OutputCopy
题目信息
题号
794D
时间限制
3 s
内存限制
256 MB
标签
DFS 及类似
图论
哈希

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。