△
InterviewTime limit1sMemory limit1024 MB
Given N, build a tree on N vertices that minimizes the sum of distances over all vertex pairs, then print that minimum and the edges.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Given a tree with vertices, build a tree that minimizes the sum of distances between all pairs of vertices. The vertices are numbered from to .
That is, the tree should minimize , where is the distance between vertices and .
Input
The first line contains the number of vertices . ()
Output
On the first line, print the minimum possible sum of distances between all pairs of vertices.
From the second line, print lines describing the edges of the tree. Each line contains the two vertex numbers connected by an edge, separated by a space. If several trees satisfy the condition, print any one of them.