CF794D.Labelling Cities

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Oleg the bank client lives in Bankopolia. There are nn cities in Bankopolia and some pair of cities are connected directly by bi-directional roads. The cities are numbered from 11 to nn . There are a total of mm roads in Bankopolia, the ii -th road connects cities uiu_{i} and viv_{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 ii is equal to xix_{i} . Then, it must hold that for all pairs of cities (u,v)(u,v) the condition xuxv<=1|x_{u}-x_{v}|<=1 holds if and only if there is a road connecting uu and vv .

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.

输入格式

The first line of input contains two space-separated integers nn and mm ( 2<=n<=31052<=n<=3·10^{5} , 1<=m<=31051<=m<=3·10^{5} ) — the number of cities and the number of roads.

Next, mm lines follow. The ii -th line contains two space-separated integers uiu_{i} and viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n , uiviu_{i}≠v_{i} ) — the cities connected by the ii -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.

输出格式

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 nn space-separated integers, x1,x2,...,xnx_{1},x_{2},...,x_{n} . The condition 1<=xi<=1091<=x_{i}<=10^{9} must hold for all ii , and for all pairs of cities (u,v)(u,v) the condition xuxv<=1|x_{u}-x_{v}|<=1 must hold if and only if there is a road connecting uu and vv .

输入输出样例

  • 输入#1

    4 4
    1 2
    1 3
    1 4
    3 4
    

    输出#1

    YES
    2 3 1 1 
    
  • 输入#2

    5 10
    1 2
    1 3
    1 4
    1 5
    2 3
    2 4
    2 5
    3 4
    3 5
    5 4
    

    输出#2

    YES
    1 1 1 1 1 
    
  • 输入#3

    4 3
    1 2
    1 3
    1 4
    

    输出#3

    NO
    

说明/提示

For the first sample, x1=2x_{1}=2 , x2=3x_{2}=3 , x3=x4=1x_{3}=x_{4}=1 is a valid labeling. Indeed, (3,4)(3,4) , (1,2)(1,2) , (1,3)(1,3) , (1,4)(1,4) are the only pairs of cities with difference of labels not greater than 11 , and these are precisely the roads of Bankopolia.

For the second sample, all pairs of cities have difference of labels not greater than 11 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.

首页