Universal Cup Judging System

Universal Cup

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

给定一棵包含 $N$ 个顶点的树 $A$。$A$ 的顶点编号为 $1, 2, \dots, N$,第 $i$ 条边 ($1 \le i \le N - 1$) 连接 $A$ 的顶点 $u_i$ 和 $v_i$。 此外,给定另一棵包含 $N$ 个顶点的树 $B$。$B$ 的顶点编号也为 $1, 2, \dots, N$,第 $j$ 条边 ($1 \le j \le N - 1$) 连接 $B$ 的顶点 $x_j$ 和 $y_j$。 你的任务是找到一对排列 $((P_1, P_2, \dots, P_{N-1}), (Q_1, Q_2, \dots, Q_{N-1}))$,满足以下条件:

  • 对于 $k = 1, 2, \dots, N - 1$,依次执行以下操作 1 和 2。在对每个 $k$ 完成操作 1 和 2 后,$A$ 和 $B$ 必须始终保持为树。

    1. 在树 $A$ 中,删除连接顶点 $u_{P_k}$ 和 $v_{P_k}$ 的边,并添加一条连接顶点 $x_{Q_k}$ 和 $y_{Q_k}$ 的边。
    2. 在树 $B$ 中,删除连接顶点 $x_{Q_k}$ 和 $y_{Q_k}$ 的边,并添加一条连接顶点 $u_{P_k}$ 和 $v_{P_k}$ 的边。

可以证明,在题目给定的约束条件下,总是存在合法的解。

输入格式

输入按以下格式给出:

$N$ $u_1 \ v_1$ $u_2 \ v_2$ $\vdots$ $u_{N-1} \ v_{N-1}$ $x_1 \ y_1$ $x_2 \ y_2$ $\vdots$ $x_{N-1} \ y_{N-1}$

  • 所有输入值均为整数。
  • $2 \le N \le 1000$
  • $1 \le u_i, v_i, x_j, y_j \le N$
  • 给定的 $A$ 和 $B$ 均为树。

输出格式

按以下格式输出答案:

$P_1 \ P_2 \ \dots \ P_{N-1}$ $Q_1 \ Q_2 \ \dots \ Q_{N-1}$

样例

样例输入 1

4
1 2
2 3
3 4
1 2
2 4
2 3

样例输出 1

3 1 2
2 1 3

样例输入 2

2
1 2
2 1

样例输出 2

1
1

样例输入 3

7
1 2
1 3
2 4
2 5
3 6
3 7
1 5
1 6
1 7
5 2
6 3
7 4

样例输出 3

1 2 3 4 5 6
1 2 6 4 5 3

说明

在第一个样例中,操作前,$A$ 是一条路径图,$B$ 是一个星形图。 在 $k = 1$ 的操作后,$A$ 变为星形图,$B$ 变为路径图。 在 $k = 2$ 的操作中,删除和添加的是同一条边(按顶点编号计),因此树的形状保持不变。 在完成 $k = 3$ 的操作后,树 $A$ 和 $B$ 的原始形状完全交换。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.