F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

KD-Graph

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 4196    Accepted Submission(s): 1186


Problem Description
Let’s call a weighted connected undirected graph of n vertices and m edges KD-Graph, if the
following conditions fulfill:

* n vertices are strictly divided into K groups, each group contains at least one vertice

* if vertices p and q ( pq ) are in the same group, there must be at least one path between p and q meet the max value in this path is less than or equal to D.

* if vertices p and q ( pq ) are in different groups, there can’t be any path between p and q meet the max value in this path is less than or equal to D.

You are given a weighted connected undirected graph G of n vertices and m edges and an integer K.

Your task is find the minimum non-negative D which can make there is a way to divide the n vertices into K groups makes G satisfy the definition of KD-Graph.Or -1 if there is no such D exist.
 

Input
The first line contains an integer T (1≤ T ≤5) representing the number of test cases.
For each test case , there are three integers n,m,k(2≤n≤100000,1≤m≤500000,1≤k≤n) in the first line.
Each of the next m lines contains three integers u, v and c (1≤v,u≤n,v≠u,1≤c≤10^9) meaning that there is an edge between vertices u and v with weight c.
 

Output
For each test case print a single integer in a new line.
 

Sample Input
2 3 2 2 1 2 3 2 3 5 3 2 2 1 2 3 2 3 3
 

Sample Output
3 -1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-04-01 09:58:28, Gzip enabled