#P7885. KD-Graph
KD-Graph
KD-Graph
Problem Description
Let’s call a weighted connected undirected graph of vertices and m edges KD-Graph, if the following conditions fulfill:
- vertices are strictly divided into groups, each group contains at least one vertice
- if vertices and ( ≠ ) are in the same group, there must be at least one path between and meet the max value in this path is less than or equal to .
- if vertices and ( ≠ ) are in different groups, there can’t be any path between and meet the max value in this path is less than or equal to . You are given a weighted connected undirected graph of vertices and edges and an integer . Your task is find the minimum non-negative which can make there is a way to divide the vertices into groups makes satisfy the definition of KD-Graph.Or if there is no such exist.
Input
The first line contains an integer (1≤ ≤5) representing the number of test cases. For each test case , there are three integers in the first line. Each of the next lines contains three integers and meaning that there is an edge between vertices and with weight .
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
2021“MINIEYE杯”中国大学生算法设计超级联赛(1)