递增标签AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a connected simple undirected graph with $N$ vertices and $M$ edges. The vertices are numbered $1,2,\ldots,N$, and the $i$-th edge connects vertices $U_i$ and $V_i$.
给定一个有 $N$ 个顶点、$M$ 条边的连通简单无向图。顶点编号为 $1,2,\ldots,N$,第 $i$ 条边连接顶点 $U_i$ 和 $V_i$。AI (CI翻译)
Construct one integer sequence $A=(A_1,A_2,\ldots,A_N)$ satisfying all of the following conditions.
请构造一个整数序列 $A=(A_1,A_2,\ldots,A_N)$,满足以下所有条件:AI (CI翻译)
$0 \le A_v \le N$for every vertex$v$.$A_1=0$.- For every vertex
$v$other than vertex$1$, there is exactly one vertex$w$adjacent to$v$satisfying$A_w=A_v-1$.
- 对每个顶点
$v$,都有$0 \le A_v \le N$。 $A_1=0$。- 对于每个顶点
$v\neq 1$,恰好存在一个与$v$相邻的顶点$w$,满足$A_w=A_v-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.
可以证明,在本题的约束条件下,至少存在一个满足上述所有条件的整数序列。如果有多个满足条件的整数序列,输出其中任意一个即可。AI (CI翻译)
$T$ test cases are given; solve each of them.
给定 $T$ 组测试用例,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \le T \le 3 \times 10^4$$1 \le N \le 3 \times 10^5$$N-1 \le M \le 3 \times 10^5$$1 \le U_i < V_i \le N$$(U_i,V_i) \neq (U_j,V_j)$if$i \neq j$.- The given graph is connected.
- The sum of
$N$in each input is at most$3 \times 10^5$. - The sum of
$M$in each input is at most$3 \times 10^5$. - All input values are integers.
$1 \le T \le 3 \times 10^4$$1 \le N \le 3 \times 10^5$$N-1 \le M \le 3 \times 10^5$$1 \le U_i < V_i \le N$- 若
$i \neq j$,则$(U_i,V_i) \neq (U_j,V_j)$。 - 给定的图是连通的。
- 每个输入中所有测试用例的
$N$之和不超过$3 \times 10^5$。 - 每个输入中所有测试用例的
$M$之和不超过$3 \times 10^5$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case:
输入从标准输入读入,格式如下,其中 $\\mathrm{case}_i$ 表示第 $i$ 组测试用例:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试用例的格式如下:AI (CI翻译)
N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M
N M
U_1 V_1
U_2 V_2
\vdots
U_M V_MAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.
输出 $T$ 行。第 $i$ 行应包含第 $i$ 组测试用例的答案。AI (CI翻译)
For each test case, output an integer sequence $A$ satisfying the conditions in the following format:
对于每组测试用例,按以下格式输出一个满足条件的整数序列 $A$:AI (CI翻译)
A_1 A_2 \dots A_N
A_1 A_2 \dots A_NAI (CI翻译)
样例
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
0 2 1 2 1 2
0
0 3 2 1 3 3
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。