Pro.ID22485 TitleA Bit Different Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22485 AC0 Submit0 Ratio- 时间&空间限制描述MST (Minimum Spanning Tree) is a common problem in graph theory. It is too easy for all of you. Now there is a problem a bit different. Given a weighted graph G(V, E), if T is a spanning trees of G. Define value(T) = max{ value(e) | e is in T } - min{ value(e) | e is in T } In this problem, you only have to output the minimum value(T). 输入The first line of the input is a positive integer C, denoting the number of test cases followed. The first line of each test case is two positive integers N ( 2 < N ≤ 200 ) and M ( M ≤ 5000 ), which represent the number of vertices and edges of G. After that, there are M lines followed. The i-th ( 1 ≤ i ≤ M ) line contains three integers Xi ( 0 < Xi ≤ N ), Yi ( 0 ≤ Yi ≤ N ), Di ( 0 < Di ≤ 108 ), which means that there is an edge from Xi to Yi and the distance of this edge is Di. You can assume that the graph G is connected and no more than one edge exists between any two vertices. 输出Description MST (Minimum Spanning Tree) is a common problem in graph theory. It is too easy for all of you. Now there is a problem a bit different. Given a weighted graph G(V, E), if T is a spanning trees of G. Define value(T) = max{ value(e) | e is in T } - min{ value(e) | e is in T } In this problem, you only have to output the minimum value(T). Input The first line of the input is a positive integer C, denoting the number of test cases followed. The first line of each test case is two positive integers N ( 2 < N ≤ 200 ) and M ( M ≤ 5000 ), which represent the number of vertices and edges of G. After that, there are M lines followed. The i-th ( 1 ≤ i ≤ M ) line contains three integers Xi ( 0 < Xi ≤ N ), Yi ( 0 ≤ Yi ≤ N ), Di ( 0 < Di ≤ 108 ), which means that there is an edge from Xi to Yi and the distance of this edge is Di. You can assume that the graph G is connected and no more than one edge exists between any two vertices. Output The output should consists of C lines, one line for each test case, only containing one integer which represents the minimum value of value( T ). No redundant spaces are needed. Sample Input 1 Sample Output 10 Source 样例输入1 样例输出10 作者 |