AT_arc224_c.Ascending Labels

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a connected simple undirected graph with NN vertices and MM edges. The vertices are numbered 1,2,…,N1,2,\ldots,N, and the ii-th edge connects vertices UiU_i and ViV_i.

Construct one integer sequence A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) satisfying all of the following conditions.

  • 0≤Av≤N0 \le A_v \le N for every vertex vv.
  • A1=0A_1=0.
  • For every vertex vv other than vertex 11, there is exactly one vertex ww adjacent to vv satisfying Aw=Av−1A_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.

TT test cases are given; solve each of them.

给你一个包含 NN 个顶点和 MM 条边的连通简单无向图。顶点编号为 1,2,…,N1,2,\ldots,N,第 ii 条边连接顶点 UiU_i 和 ViV_i。

请构造一个整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N),使其满足以下所有条件:

  • 对每个顶点 vv,均有 0≤Av≤N0 \le A_v \le N;
  • A1=0A_1 = 0;
  • 对除顶点 11 外的每个顶点 vv,恰好存在一个与 vv 相邻的顶点 ww,使得 Aw=Av−1A_w = A_v - 1。

在本题的约束条件下,可以证明至少存在一个满足上述所有条件的整数序列。若存在多个满足条件的序列,则输出任意一个即可。

共给出 TT 组测试数据,请对每组数据求解。

输入格式

The input is given from Standard Input in the following format, where casei\mathrm{case}_i denotes the ii-th test case:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN MM
U1U_1 V1V_1
U2U_2 V2V_2
⋮\vdots
UMU_M VMV_M

输入从标准输入给出,格式如下,其中 casei\mathrm{case}_i 表示第 ii 个测试用例:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例的格式如下:

NN MM
U1U_1 V1V_1
U2U_2 V2V_2
⋮\vdots
UMU_M VMV_M

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

For each test case, output an integer sequence AA satisfying the conditions in the following format:

A1A_1 A2A_2 …\dots ANA_N

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

对每个测试用例,按以下格式输出一个满足条件的整数序列 AA:

A1A_1 A2A_2 …\dots ANA_N

输入输出样例

  • 输入#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)A=(0,2,1,2,1,2).

  • For vertex 11, A1=0A_1=0.
  • For vertex 22, there is only one adjacent vertex ww satisfying Aw=A2−1A_w=A_2-1, which is vertex 55.
  • For vertex 33, there is only one adjacent vertex ww satisfying Aw=A3−1A_w=A_3-1, which is vertex 11.
  • For vertex 44, there is only one adjacent vertex ww satisfying Aw=A4−1A_w=A_4-1, which is vertex 33.
  • For vertex 55, there is only one adjacent vertex ww satisfying Aw=A5−1A_w=A_5-1, which is vertex 11.
  • For vertex 66, there is only one adjacent vertex ww satisfying Aw=A6−1A_w=A_6-1, which is vertex 33.

Thus, this integer sequence AA satisfies the conditions in the problem statement.

Additionally, setting A=(0,3,1,2,2,2)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 vv outside each vertex and AvA_v inside each vertex.

Constraints

  • 1≤T≤3×1041 \le T \le 3 \times 10^4
  • 1≤N≤3×1051 \le N \le 3 \times 10^5
  • N−1≤M≤3×105N-1 \le M \le 3 \times 10^5
  • 1≤Ui<Vi≤N1 \le U_i < V_i \le N
  • (Ui,Vi)≠(Uj,Vj)(U_i,V_i) \neq (U_j,V_j) if i≠ji \neq j.
  • The given graph is connected.
  • The sum of NN in each input is at most 3×1053 \times 10^5.
  • The sum of MM in each input is at most 3×1053 \times 10^5.
  • All input values are integers.

样例 1 解释:
该输入包含三个测试用例。

对于第一个测试用例,考虑设定 A=(0,2,1,2,1,2)A=(0,2,1,2,1,2)。

  • 对于顶点 11,有 A1=0A_1=0。
  • 对于顶点 22,满足 Aw=A2−1A_w=A_2-1 的相邻顶点 ww 恰好只有一个,即顶点 55。
  • 对于顶点 33,满足 Aw=A3−1A_w=A_3-1 的相邻顶点 ww 恰好只有一个,即顶点 11。
  • 对于顶点 44,满足 Aw=A4−1A_w=A_4-1 的相邻顶点 ww 恰好只有一个,即顶点 33。
  • 对于顶点 55,满足 Aw=A5−1A_w=A_5-1 的相邻顶点 ww 恰好只有一个,即顶点 11。
  • 对于顶点 66,满足 Aw=A6−1A_w=A_6-1 的相邻顶点 ww 恰好只有一个,即顶点 33。

因此,该整数序列 AA 满足题目描述中的条件。

此外,设定 A=(0,3,1,2,2,2)A=(0,3,1,2,2,2) 同样满足条件,故输出 0 3 1 2 2 2 也被接受。

下图展示了样例输出中每个测试用例的图示:每个顶点外部标注其顶点编号 vv,内部标注对应的 AvA_v 值。

约束条件

  • 1≤T≤3×1041 \le T \le 3 \times 10^4
  • 1≤N≤3×1051 \le N \le 3 \times 10^5
  • N−1≤M≤3×105N-1 \le M \le 3 \times 10^5
  • 1≤Ui<Vi≤N1 \le U_i < V_i \le N
  • 若 i≠ji \neq j,则 (Ui,Vi)≠(Uj,Vj)(U_i,V_i) \neq (U_j,V_j)。
  • 给定图是连通的。
  • 所有输入中 NN 的总和不超过 3×1053 \times 10^5。
  • 所有输入中 MM 的总和不超过 3×1053 \times 10^5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页