AT_arc224_c.Ascending Labels
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a connected simple undirected graph with N vertices and M edges. The vertices are numbered 1,2,…,N, and the i-th edge connects vertices Ui and Vi.
Construct one integer sequence A=(A1,A2,…,AN) satisfying all of the following conditions.
- 0≤Av≤N for every vertex v.
- A1=0.
- For every vertex v other than vertex 1, there is exactly one vertex w adjacent to v satisfying Aw=Av−1.
It can be proved that under the constraints of this problem, there exists at least one integer sequence satisfying all of the above conditions. If there are multiple integer sequences satisfying the conditions, any of them will be accepted.
T test cases are given; solve each of them.
给你一个包含 N 个顶点和 M 条边的连通简单无向图。顶点编号为 1,2,…,N,第 i 条边连接顶点 Ui 和 Vi。
请构造一个整数序列 A=(A1,A2,…,AN),使其满足以下所有条件:
- 对每个顶点 v,均有 0≤Av≤N;
- A1=0;
- 对除顶点 1 外的每个顶点 v,恰好存在一个与 v 相邻的顶点 w,使得 Aw=Av−1。
在本题的约束条件下,可以证明至少存在一个满足上述所有条件的整数序列。若存在多个满足条件的序列,则输出任意一个即可。
共给出 T 组测试数据,请对每组数据求解。
输入格式
The input is given from Standard Input in the following format, where casei denotes the i-th test case:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N M
U1 V1
U2 V2
⋮
UM VM
输入从标准输入给出,格式如下,其中 casei 表示第 i 个测试用例:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N M
U1 V1
U2 V2
⋮
UM VM
输出格式
Output T lines. The i-th line should contain the answer for the i-th test case.
For each test case, output an integer sequence A satisfying the conditions in the following format:
A1 A2 … AN
输出 T 行。第 i 行应包含第 i 个测试用例的答案。
对每个测试用例,按以下格式输出一个满足条件的整数序列 A:
A1 A2 … AN
输入输出样例
输入#1
3 6 7 1 5 1 3 3 5 2 5 3 4 3 6 4 6 1 0 6 10 4 6 1 4 2 5 3 6 1 3 1 2 2 3 2 4 3 4 3 5
输出#1
0 2 1 2 1 2 0 0 3 2 1 3 3
说明/提示
Sample 1 Explanation:
This input contains three test cases.
For the first test case, consider setting A=(0,2,1,2,1,2).
- For vertex 1, A1=0.
- For vertex 2, there is only one adjacent vertex w satisfying Aw=A2−1, which is vertex 5.
- For vertex 3, there is only one adjacent vertex w satisfying Aw=A3−1, which is vertex 1.
- For vertex 4, there is only one adjacent vertex w satisfying Aw=A4−1, which is vertex 3.
- For vertex 5, there is only one adjacent vertex w satisfying Aw=A5−1, which is vertex 1.
- For vertex 6, there is only one adjacent vertex w satisfying Aw=A6−1, which is vertex 3.
Thus, this integer sequence A satisfies the conditions in the problem statement.
Additionally, setting A=(0,3,1,2,2,2) also satisfies the conditions, so the output 0 3 1 2 2 2 is also accepted.
The figure below shows, for each test case in the sample output, the vertex number v outside each vertex and Av inside each vertex.

Constraints
- 1≤T≤3×104
- 1≤N≤3×105
- N−1≤M≤3×105
- 1≤Ui<Vi≤N
- (Ui,Vi)=(Uj,Vj) if i=j.
- The given graph is connected.
- The sum of N in each input is at most 3×105.
- The sum of M in each input is at most 3×105.
- All input values are integers.
样例 1 解释:
该输入包含三个测试用例。
对于第一个测试用例,考虑设定 A=(0,2,1,2,1,2)。
- 对于顶点 1,有 A1=0。
- 对于顶点 2,满足 Aw=A2−1 的相邻顶点 w 恰好只有一个,即顶点 5。
- 对于顶点 3,满足 Aw=A3−1 的相邻顶点 w 恰好只有一个,即顶点 1。
- 对于顶点 4,满足 Aw=A4−1 的相邻顶点 w 恰好只有一个,即顶点 3。
- 对于顶点 5,满足 Aw=A5−1 的相邻顶点 w 恰好只有一个,即顶点 1。
- 对于顶点 6,满足 Aw=A6−1 的相邻顶点 w 恰好只有一个,即顶点 3。
因此,该整数序列 A 满足题目描述中的条件。
此外,设定 A=(0,3,1,2,2,2) 同样满足条件,故输出 0 3 1 2 2 2 也被接受。
下图展示了样例输出中每个测试用例的图示:每个顶点外部标注其顶点编号 v,内部标注对应的 Av 值。

约束条件
- 1≤T≤3×104
- 1≤N≤3×105
- N−1≤M≤3×105
- 1≤Ui<Vi≤N
- 若 i=j,则 (Ui,Vi)=(Uj,Vj)。
- 给定图是连通的。
- 所有输入中 N 的总和不超过 3×105。
- 所有输入中 M 的总和不超过 3×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?