#P14620. [2019 KAIST RUN Fall] Minimum Diameter Spanning Tree
[2019 KAIST RUN Fall] Minimum Diameter Spanning Tree
题目描述
You are given a simple connected undirected weighted graph with nodes and edges. Each node is numbered 1 through .
A spanning tree of is a subgraph of , which is a tree and connects all the vertices of . 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 is a spanning tree of that has a minimum diameter.
Write a program that finds any minimum diameter spanning tree.
输入格式
The first line of the input contains two integers () and ().
Then lines follow: The ()-th line contains three space-separated integers , and (, ); it describes a bidirectional edge connecting vertex and vertex with length .
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 .
In the next lines, print the description of the edges in the minimum diameter spanning tree of . The ()-th line should contain two space-separated integers and (); it describes a bidirectional edge connecting vertex and .
If there are several possible answers, print any one of them.
3 3
1 2 1
2 3 1
3 1 1
2
1 2
3 1
6 7
1 2 10
2 3 20
1 3 30
3 4 1000
4 5 30
5 6 20
4 6 10
1060
3 4
6 4
5 6
2 3
1 2
京公网安备 11011102002149号