#P7903. 兜心の顶

    ID: 8939 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>2021Special JudgeO2优化洛谷月赛

兜心の顶

Background

Source: Eight Immortals Toasting, this can be clicked.

  • Lü Dongbin — Drunkenly lifting a kettle, strength like a thousand jin;
  • Tieguai Li — Spinning elbow and knee strike, drunk yet still real;
  • Han Zhongli — Stumbling steps, hugging the jar, Douxin Top;
  • Lan Caihe — One-hand toast, breaking at the waist;
  • Zhang Guolao — Drunkenly tossing a cup, continuous kicking combo;
  • Cao Guojiu — Immortal’s toast, throat-locking hook;
  • Han Xiangzi — Grabbing the wrist and striking the chest, drunkenly playing the flute;
  • He Xiangu — Bending the waist to offer wine, drunkenly swaying steps.

Problem Description

Given a positive integer nn, you need to construct a tree with nn nodes such that the centroid of the tree’s diameter is not the centroid of the tree.

At the same time, this tree must satisfy: the diameter1^1, the centroid2^2, and the centroid of the diameter3^3 are all unique.


Notes:

Input Format

The first line contains a positive integer nn, the number of nodes in the tree.

Output Format

Output a positive integer nn on the first line.

Then output n−1n-1 lines. Each line contains two positive integers u,vu, v, representing an edge of the tree.

If there is no solution, output -1.

This problem uses a Special Judge. Any valid solution will be accepted.

20
20
20 18
1 3
19 12
19 4
16 1
4 1
1 7
16 10
7 20
13 8
10 2
18 13
13 17
14 18
11 19
16 5
2 6
16 9
17 15
2
-1

Hint

Sample Explanation

In Sample #1, the centroid of the diameter is 77, and the centroid of the tree is 11. Thus, 1≠71 \ne 7.

In Sample #2, n=2n = 2. With only two nodes, the centroid is obviously impossible to be unique.

Constraints

This problem uses bundled testdata.

Subtask ID Score Special Property
11 3030 n≤10n \le 10
22 nn is odd
33 nn is even
44 1010 None

For 100%100\% of the testdata: 1≤n≤1041 \le n \le 10^4.

The Special Judge source code is provided; see the attachment below.

Translated by ChatGPT 5