CF398C.Tree and Array
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
User ainta likes trees. This time he is going to make an undirected tree with n vertices numbered by integers from 1 to n. The tree is weighted, so each edge of the tree will have some integer weight.
Also he has an array t: t[1], t[2], ..., t[n]. At first all the elements of the array are initialized to 0. Then for each edge connecting vertices u and v (u < v) of the tree with weight c, ainta adds value c to the elements t[u], t[u + 1], ..., t[v - 1], t[v] of array t.
Let's assume that d(u, v) is the total weight of edges on the shortest path between vertex u and vertex v. User ainta calls a pair of integers x, y (1 ≤ x < y ≤ n) good if and only if d(x, y) = t[x] + t[x + 1] + ... + t[y - 1] + t[y].
User ainta wants to make at least
good pairs, but he couldn't make a proper tree. Help ainta to find such a tree.
用户 ainta 喜欢树。这次他要构造一棵包含 $ n $ 个顶点的无向树,顶点编号为 $ 1 $ 到 $ n $。该树是带权的,因此树中的每条边都具有某个整数权重。
此外,他还拥有一个数组 $ t : t[1],,t[2],,\dots,,t[n] $。初始时,数组中所有元素均设为 $ 0 $。接着,对于树中任意一条连接顶点 $ u $ 和 $ v $(其中 $ u < v $)且权重为 $ c $ 的边,ainta 将值 $ c $ 加到数组 $ t $ 的元素 $ t[u],,t[u+1],,\dots,,t[v-1],,t[v] $ 上。
设 $ d(u,,v) $ 表示顶点 $ u $ 与顶点 $ v $ 之间最短路径上所有边的权重之和。用户 ainta 称一对整数 $ x,,y $(满足 $ 1 \le x < y \le n $)为“好”的,当且仅当
d(x,y)=t[x]+t[x+1]+⋯+t[y−1]+t[y].
用户 ainta 希望构造出至少
对“好”的数对,但他未能成功构造出满足条件的树。请帮助 ainta 找到这样一棵树。
输入格式
The first line contains a single integer n (5 ≤ n ≤ 105).
第一行包含一个整数 n(5 ≤ n ≤ 105)。
输出格式
Print n - 1 lines containing the description of the edges. The i-th line should contain three space-separated integers u__i, v__i, c__i (1 ≤ u__i < v__i ≤ n; 1 ≤ c__i ≤ 105) — two vertices connected by the edge, and the weight of the edge.
Next print
lines containing the good pairs. The k-th line should contain two space-separated integers x__k and y__k (1 ≤ x__k < y__k ≤ n). Of course, x__k, y__k must be a good pair. All pairs should be distinct — that is, for all j, k
, x__j ≠ x__k or y__j ≠ y__k must be satisfied.
If there are many correct solutions, print any of them.
输出 n - 1 行,每行描述一条边。第 i 行应包含三个以空格分隔的整数 u__i, v__i, c__i(其中 1 ≤ u__i < v__i ≤ n;1 ≤ c__i ≤ 10⁵),分别表示该边所连接的两个顶点及其权重。
接下来输出
行,每行描述一个“好对”(good pair)。第 k 行应包含两个以空格分隔的整数 x__k 和 y__k(其中 1 ≤ x__k < y__k ≤ n)。显然,(x__k, y__k) 必须是一个好对。所有输出的好对必须互不相同——即对任意 j, k,需满足
,x__j ≠ x__k 或 y__j ≠ y__k。
若存在多个正确解,输出任意一个即可。
输入输出样例
输入#1
7
输出#1
1 4 1 1 2 2 2 3 5 3 5 3 2 6 2 6 7 3 4 5 5 6 5 7
说明/提示
⌊x⌋ is the largest integer not greater than x.
You can find the definition of a tree by the following link: http://en.wikipedia.org/wiki/Tree_(graph_theory)
You can also find the definition of the shortest path by the following link: http://en.wikipedia.org/wiki/Shortest_path_problem
The tree and the array t in the sample output look like this:

⌊x⌋ 是不大于 x 的最大整数。
树的定义可参考以下链接:http://en.wikipedia.org/wiki/Tree_(graph_theory)
最短路径的定义可参考以下链接:http://en.wikipedia.org/wiki/Shortest_path_problem
样例输出中的树和数组 t 如下图所示:

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