CF398C.Tree and Array

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

User ainta likes trees. This time he is going to make an undirected tree with nn vertices numbered by integers from 11 to nn . The tree is weighted, so each edge of the tree will have some integer weight.

Also he has an array tt : t[1],t[2],...,t[n]t[1],t[2],...,t[n] . At first all the elements of the array are initialized to 00 . Then for each edge connecting vertices uu and vv ( u<v ) of the tree with weight cc , ainta adds value cc to the elements t[u],t[u+1],...,t[v1],t[v]t[u],t[u+1],...,t[v-1],t[v] of array tt .

Let's assume that d(u,v)d(u,v) is the total weight of edges on the shortest path between vertex uu and vertex vv . User ainta calls a pair of integers x,yx,y ( 1<=x<y<=n ) good if and only if d(x,y)=t[x]+t[x+1]+...+t[y1]+t[y]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.

输入格式

The first line contains a single integer nn ( 5<=n<=1055<=n<=10^{5} ).

输出格式

Print n1n-1 lines containing the description of the edges. The ii -th line should contain three space-separated integers ui,vi,ciu_{i},v_{i},c_{i} ( 1<=u_{i}<v_{i}<=n; 1<=c_{i}<=10^{5} ) — two vertices connected by the edge, and the weight of the edge.

Next print lines containing the good pairs. The kk -th line should contain two space-separated integers xkx_{k} and yky_{k} ( 1<=x_{k}<y_{k}<=n ). Of course, xk,ykx_{k},y_{k} must be a good pair. All pairs should be distinct — that is, for all j,kj,k , xjxkx_{j}≠x_{k} or yjyky_{j}≠y_{k} must be satisfied.

If there are many correct solutions, print any of them.

输入输出样例

  • 输入#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⌊x⌋ is the largest integer not greater than xx .

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 tt in the sample output look like this:

首页