CF1278E.Tests for problem D

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

We had a really tough time generating tests for problem D. In order to prepare strong tests, we had to solve the following problem.

Given an undirected labeled tree consisting of nn vertices, find a set of segments such that:

  1. both endpoints of each segment are integers from 11 to 2n2n, and each integer from 11 to 2n2n should appear as an endpoint of exactly one segment;
  2. all segments are non-degenerate;
  3. for each pair (i,j)(i, j) such that i≠ji \ne j, i∈[1,n]i \in [1, n] and j∈[1,n]j \in [1, n], the vertices ii and jj are connected with an edge if and only if the segments ii and jj intersect, but neither segment ii is fully contained in segment jj, nor segment jj is fully contained in segment ii.

Can you solve this problem too?

我们为问题 D 构造测试数据时遇到了极大的困难。为了准备强测试数据,我们必须解决如下问题:

给定一棵包含 nn 个顶点的无向带标号树,求一组线段,使得:

  1. 每条线段的两个端点均为 11 到 2n2n 之间的整数,且 11 到 2n2n 中的每个整数恰好作为某一条线段的一个端点出现;
  2. 所有线段均为非退化线段(即长度严格大于 0);
  3. 对任意满足 i≠ji \ne j、i∈[1,n]i \in [1, n] 且 j∈[1,n]j \in [1, n] 的数对 (i,j)(i, j),顶点 ii 与 jj 在树中相邻当且仅当线段 ii 与线段 jj 相交,但线段 ii 不完全包含于线段 jj 内,且线段 jj 也不完全包含于线段 ii 内。

你也能解决这个问题吗?

输入格式

The first line contains one integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5) — the number of vertices in the tree.

Then n−1n - 1 lines follow, each containing two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n, xi≠yix_i \ne y_i) denoting the endpoints of the ii-th edge.

It is guaranteed that the given graph is a tree.

第一行包含一个整数 nn(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5)——树中顶点的数量。

接下来是 n−1n - 1 行,每行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤n1 \le x_i, y_i \le n,且 xi≠yix_i \ne y_i),表示第 ii 条边的两个端点。

保证给定的图是一棵树。

输出格式

Print nn pairs of integers, the ii-th pair should contain two integers lil_i and rir_i (1≤li<ri≤2n1 \le l_i \lt r_i \le 2n) — the endpoints of the ii-th segment. All 2n2n integers you print should be unique.

It is guaranteed that the answer always exists.

输出 nn 对整数,其中第 ii 对应包含两个整数 lil_i 和 rir_i(满足 1≤li<ri≤2n1 \le l_i \lt r_i \le 2n),即第 ii 条线段的两个端点。你所输出的全部 2n2n 个整数必须互不相同。

保证答案一定存在。

输入输出样例

  • 输入#1

    6
    1 2
    1 3
    3 4
    3 5
    2 6

    输出#1

    9 12
    7 10
    3 11
    1 5
    2 4
    6 8
  • 输入#2

    1

    输出#2

    1 2

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

首页