CF1205D.Almost All

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a tree with nn nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:

For every two nodes ii, jj, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from 11 to ⌊2n29⌋\lfloor \frac{2n^2}{9} \rfloor has to be written on the blackboard at least once.

It is guaranteed that such an arrangement exists.

给你一棵包含 nn 个节点的树。你需要在它的每条边上写上一个非负整数,使得以下条件成立:

对于任意两个节点 ii、jj,考察它们之间的唯一路径,并计算该路径上所有边所写数字之和。将所有这样得到的和写在黑板上。那么,黑板上必须至少出现一次从 11 到 ⌊2n29⌋\lfloor \frac{2n^2}{9} \rfloor 的每一个整数。

题目保证这样的赋值方案一定存在。

输入格式

The first line contains a single integer nn (1≤n≤10001 \le n \le 1000) — the number of nodes.

Each of the next n−1n-1 lines contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n, u≠vu \neq v), meaning that there is an edge between nodes uu and vv. It is guaranteed that these edges form a tree.

第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)—— 表示节点的数量。

接下来的 n−1n-1 行,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n,且 u≠vu \neq v),表示节点 uu 与节点 vv 之间存在一条边。保证这些边构成一棵树。

输出格式

Output n−1n-1 lines, each of form uu vv xx (0≤x≤1060 \le x \le 10^6), which will mean that you wrote number xx on the edge between uu, vv.

Set of edges (u,v)(u, v) has to coincide with the set of edges of the input graph, but you can output edges in any order. You can also output ends of edges in an order different from the order in input.

输出 n−1n-1 行,每行格式为 uu vv xx(其中 0≤x≤1060 \le x \le 10^6),表示你在顶点 uu 与 vv 之间的边上写下了数字 xx。

所输出的边集 (u,v)(u, v) 必须与输入图的边集完全一致,但你可以以任意顺序输出这些边;此外,每条边的两个端点 uu、vv 的顺序也可以与输入中不同。

输入输出样例

  • 输入#1

    3
    2 3
    2 1

    输出#1

    3 2 1
    1 2 2
  • 输入#2

    4
    2 4
    2 3
    2 1

    输出#2

    4 2 1
    3 2 2
    1 2 3
  • 输入#3

    5
    1 2
    1 3
    1 4
    2 5

    输出#3

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

说明/提示

In the first example, distance between nodes 11 and 22 is equal to 22, between nodes 22 and 33 to 11, between 11 and 33 to 33.

In the third example, numbers from 11 to 99 (inclusive) will be written on the blackboard, while we need just from 11 to 55 to pass the test.

在第一个例子中,节点 11 与节点 22 之间的距离为 22,节点 22 与节点 33 之间的距离为 11,节点 11 与节点 33 之间的距离为 33。

在第三个例子中,黑板上将写下从 11 到 99(含)的所有数字,而我们只需从 11 到 55 即可通过测试。

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

首页