# Shortest-path tree

树分治。


# Shortest-path tree

Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 130712/130712 K (Java/Others) Total Submission(s): 146 Accepted Submission(s): 47

Problem Description

Given a connected, undirected graph G, a shortest-path tree rooted at vertex v is a spanning tree T of G, such that the path distance from root v to any other vertex u in T is the shortest path distance from v to u in G. We may construct a shortest-path tree using the following method: We consider a shortest-path tree rooted at node 1. For every node i in the graph G, we choose a shortest path from root to i. If there are many shortest paths from root to i, we choose the one that the sequence of passing nodes’ number is lexicographically minimum. All edges on the paths that we chose form a shortest-path tree. Now we want to know how long are the longest simple paths which contain K nodes in the shortest-path tree and how many these paths? Two simple paths are different if the sets of nodes they go through are different.

Input

The first line has a number T (T <= 10), indicating the number of test cases. For each test case, the first line contains three integers n, m, k(1<=n<=30000,1<=m<=60000,2<=k<=n), denote the number of nodes, the number of edges and the nodes of required paths. Then next m lines, each lines contains three integers a, b, c(1<=a, b<=n, 1<=c<=10000),denote there is an edge between a, b and length is c.

Output

For each case, output two numbers, denote the length of required paths and the numbers of required paths.

Sample Input

1 6 6 4 1 2 1 2 3 1 3 4 1 2 5 1 3 6 1 5 6 1

Sample Output

3 4

Author

FZU

Source

2014 Multi-University Training Contest 1

首先跑一下堆优化的Dij 或者SPFA 把树搞出来。   树搞出来以后就是树分治了。 一颗一颗子树加入。每次都找重心。 树分治写起来要小心，很容易T的。 树分治还需要多练习了。

------ 本文结束------
• 本文作者： kuangbin
• 本文链接： 291.html
• 版权声明： 本博客所有文章除特别声明外，均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处！
0%