This page is still under construction.

Parts of this page are still being built. What you see may change.

Cloud Bridge

Time limit1sMemory limit1024 MB

Summary
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.
Level

Medium6 of 10

Topics
Tree, Graph, Greedy, BFS
Solved
No attempts yet

Problem

Sunlin Internet High School has several buildings and cloud bridges that connect them.

Specifically, there are NN buildings numbered 11 through NN, and N−1N-1 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 N−1N-1 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 NN.

From the second line through the N−1N-1-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 KK of additional cloud bridges Nohyeon must build to make the school's diameter as small as possible. (0≤K≤N−10 \le K \le N-1)

On the second line, print the school's diameter RR after Nohyeon builds the KK additional cloud bridges in the manner printed below.

From the third line through the KK-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 RR, and this value RR equals the minimum diameter achievable by building at most N−1N-1 cloud bridges, the output is judged correct.

Constraints

  • 2≤N≤3002 \leq N \leq 300
  • No two cloud bridges connect the same pair of buildings.

Examples1

  1. Example 1

    Input
    3
    1 2
    2 3
    
    Expected output
    1
    1
    1 3