Cloud Bridge
Time limit1sMemory limit1024 MB
Given a tree with N nodes, add at most N-1 edges to minimize the resulting graph's diameter, and output the number of edges, the diameter, and the edges.
Problem
Sunlin Internet High School has several buildings and cloud bridges that connect them.
Specifically, there are buildings numbered through , and cloud bridges, each connecting two distinct buildings.
All buildings are connected directly or indirectly through the cloud bridges.
Jeonghwi, the winner of the 2019 Cheonha Jaeil Civil Engineering Competition, felt that there were too few cloud bridges, making it hard to move between buildings.
So Jeonghwi hired Nohyeon, the runner-up of 2018, to build additional cloud bridges.
Nohyeon must build at most additional cloud bridges so that the diameter of Sunlin Internet High School becomes as small as possible.
The diameter of the school is the maximum number of cloud bridges one must pass through when traveling between two buildings using only cloud bridges.
How should the cloud bridges be built to make the diameter as small as possible?
Input
The first line gives the number of buildings .
From the second line through the -th line, the numbers of two distinct buildings connected by an existing cloud bridge are given, one pair per line.
Output
On the first line, print the number of additional cloud bridges Nohyeon must build to make the school's diameter as small as possible. ()
On the second line, print the school's diameter after Nohyeon builds the additional cloud bridges in the manner printed below.
From the third line through the -th line, print the numbers of two distinct buildings that each cloud bridge to be built will connect, one pair per line.
All printed cloud bridges must be distinct, and an existing cloud bridge cannot be built again.
If building the cloud bridges in the printed manner makes the school's diameter , and this value equals the minimum diameter achievable by building at most cloud bridges, the output is judged correct.
Constraints
- No two cloud bridges connect the same pair of buildings.