Minimum Diameter Spanning Tree

가중치가 있는 연결 그래프에서 가장 긴 경로의 길이(지름)가 최소가 되는 신장 트리를 찾아, 그 지름과 트리의 간선들을 출력한다.

어려움9그래프최단 경로최소 신장 트리그리디아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

You are given a simple connected undirected weighted graph GG with NN nodes and MM edges. Each node is numbered 1 through NN.

A spanning tree of GG is a subgraph of GG, which is a tree and connects all the vertices of GG. The diameter of a tree is the length of the longest path among the paths between any two nodes in the tree. A minimum diameter spanning tree of GG is a spanning tree of GG that has a minimum diameter.

Write a program that finds any minimum diameter spanning tree.

입력

The first line of the input contains two integers NN (2N5002 \le N \le 500) and MM (N1MN(N1)2N-1 \le M \le \frac{N(N-1)}{2}).

Then MM lines follow: The ii (1iM1 \le i \le M)-th line contains three space-separated integers u_iu\_i, v_iv\_i and l_il\_i (1u_i,v_iN1 \le u\_i, v\_i \le N, 1l_i1091 \le l\_i \le 10^9); it describes a bidirectional edge connecting vertex u_iu\_i and vertex v_iv\_i with length l_il\_i.

It is guaranteed that the given graph doesn't have any loops or multiple edges, and the graph is connected.

출력

In the first line, print the diameter of the minimum diameter spanning tree of GG

In the next N1N-1 lines, print the description of the edges in the minimum diameter spanning tree of GG. The jj (1jN11 \le j \le N-1)-th line should contain two space-separated integers x_ix\_i and y_iy\_i (1x_i, y_iN1 \le x\_i,\ y\_i \le N); it describes a bidirectional edge connecting vertex x_ix\_i and y_iy\_i

If there are several possible answers, print any one of them.