CF1205D.Almost All
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:
For every two nodes i, j, 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 1 to ⌊92n2⌋ has to be written on the blackboard at least once.
It is guaranteed that such an arrangement exists.
给你一棵包含 n 个节点的树。你需要在它的每条边上写上一个非负整数,使得以下条件成立:
对于任意两个节点 i、j,考察它们之间的唯一路径,并计算该路径上所有边所写数字之和。将所有这样得到的和写在黑板上。那么,黑板上必须至少出现一次从 1 到 ⌊92n2⌋ 的每一个整数。
题目保证这样的赋值方案一定存在。
输入格式
The first line contains a single integer n (1≤n≤1000) — the number of nodes.
Each of the next n−1 lines contains two integers u and v (1≤u,v≤n, u=v), meaning that there is an edge between nodes u and v. It is guaranteed that these edges form a tree.
第一行包含一个整数 n(1≤n≤1000)—— 表示节点的数量。
接下来的 n−1 行,每行包含两个整数 u 和 v(1≤u,v≤n,且 u=v),表示节点 u 与节点 v 之间存在一条边。保证这些边构成一棵树。
输出格式
Output n−1 lines, each of form u v x (0≤x≤106), which will mean that you wrote number x on the edge between u, v.
Set of edges (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−1 行,每行格式为 u v x(其中 0≤x≤106),表示你在顶点 u 与 v 之间的边上写下了数字 x。
所输出的边集 (u,v) 必须与输入图的边集完全一致,但你可以以任意顺序输出这些边;此外,每条边的两个端点 u、v 的顺序也可以与输入中不同。
输入输出样例
输入#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 1 and 2 is equal to 2, between nodes 2 and 3 to 1, between 1 and 3 to 3.
In the third example, numbers from 1 to 9 (inclusive) will be written on the blackboard, while we need just from 1 to 5 to pass the test.
在第一个例子中,节点 1 与节点 2 之间的距离为 2,节点 2 与节点 3 之间的距离为 1,节点 1 与节点 3 之间的距离为 3。
在第三个例子中,黑板上将写下从 1 到 9(含)的所有数字,而我们只需从 1 到 5 即可通过测试。
输入解题思路,AI测评打分。不知道怎么写?