#6876. [2019 KAIST RUN Fall] Minimum Diameter Spanning Tree

    ID: 6876 传统题 5000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P14620图论2019Special Judge最短路高校校赛

[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 $G$ with $N$ nodes and $M$ edges. Each node is numbered 1 through $N$.

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 $N$ ($2 \le N \le 500$) and $M$ ($N-1 \le M \le \frac{N(N-1)}{2}$).

Then MM lines follow: The ii (1≤i≤M1 \le i \le M)-th line contains three space-separated integers uiu_i, viv_i and lil_i (1≤ui,vi≤N1 \le u_i, v_i \le N, 1≤li≤1091 \le l_i \le 10^9); it describes a bidirectional edge connecting vertex uiu_i and vertex viv_i with length lil_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 $G$.

In the next N−1N-1 lines, print the description of the edges in the minimum diameter spanning tree of GG. The jj (1≤j≤N−11 \le j \le N-1)-th line should contain two space-separated integers xix_i and yiy_i (1≤xi,yi≤N1 \le x_i, y_i \le N); it describes a bidirectional edge connecting vertex xix_i and yiy_i.

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

提示

(暂无提示) 标签: P14620|图论|2019|Special Judge|最短路|高校校赛

来源

P14620|[2019 KAIST RUN Fall] Minimum Diameter Spanning Tree