CF794D.Labelling Cities
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
银行客户奥列格生活在银行城(Bankopolia)。银行城共有 n 座城市,其中某些城市对之间由双向道路直接相连。城市编号为 1 到 n。银行城一共有 m 条道路,其中第 i 条道路连接城市 ui 和 vi。保证从任意一座城市出发,均可经由若干条道路到达其他任意一座城市。
奥列格希望为每座城市分配一个标签。设城市 i 的标签为 xi。那么,必须满足如下条件:对任意一对城市 (u,v),恒有 ∣xu−xv∣≤1 当且仅当 u 与 v 之间存在一条直接道路。
奥列格想知道是否存在满足上述条件的标签分配方案。若存在,请给出一种可行的标签方案;否则,请说明该任务不可能完成。
输入格式
The first line of input contains two space-separated integers n and m (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105) — 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.
输入的第一行包含两个用空格分隔的整数 n 和 m(2 ≤ n ≤ 3⋅105,1 ≤ m ≤ 3⋅105)——分别表示城市的数量和道路的数量。
接下来是 m 行。第 i 行包含两个用空格分隔的整数 ui 和 vi(1 ≤ ui,vi ≤ n,ui = vi)——表示第 i 条道路所连接的两座城市。保证任意两座城市之间至多只有一条道路,并且通过若干条道路可以从任意一座城市到达其他任意一座城市。
输出格式
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 ≤ 109 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.
如果无法完成所需的标号,则输出一行字符串 "NO"(不带引号)。
否则,第一行输出字符串 "YES"(不带引号);第二行输出 n 个用空格分隔的整数 x1,x2,...,xn。需满足对所有 i 有 1≤xi≤109,且对所有城市对 (u,v),当且仅当 u 与 v 之间存在道路连接时,满足 ∣xu−xv∣≤1。
输入输出样例
输入#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, _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.
对于第一个样例,x1=2,x2=3,x3=x4=1 是一种合法的标号方案。事实上,(3,4)、(1,2)、(1,3)、(1,4) 是唯一满足标号差值不超过 1 的城市对,而这些恰好就是 Bankopolia 中的所有道路。
对于第二个样例,所有城市对的标号差值均不超过 1,且所有城市对之间均存在一条道路相连。
对于最后一个样例,无法构造出满足给定约束条件的标号方案。
输入解题思路,AI测评打分。不知道怎么写?