xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛

#1235 : New Teaching Buildings

时间限制:2000ms
单点时限:2000ms
内存限制:256MB

描述

Thanks to the generous finance income, Programming Monkey Elementary School is going to build three new teaching buildings.

The school could be seen as a connected graph with n vertices and m edges, in which every vertex belongs to at most a single cycle(the one consists of a sequence of vertices starting and ending at the same vertex, with each two consecutive vertices in the sequence adjacent to each other in the graph and no repetitions of vertices other than the repetition of starting and ending vertex.). For the sake of students’ physical well-being, the principal decides to find the longest “Y shape road” in the school and build the three new buildings in its three ends. A “Y shape road” contains three simple roads in the graph, which begins from a same vertex and don’t have any common vertices except it. As we know, a simple road is a finite sequence of edges which connect a sequence of vertices which are all distinct from one another. The longest one is exactly the one contains the largest length of roads.

Can you help him?

输入

There are no more than 600 test cases, and most cases are very small.

The first line of the input contains an integer T which means the number of test cases.

The first line of each test case contains two integers, n, m, which are the number of vertices and the number of edges. All vertices are numbered from 1 to n.

The next m lines, each line consists of three integers, u, v, w, which means there is an undirected edge between u and v, and its length is w.

Please note that n ≤ 100,000,w ≤ 1000

输出

For each test case, output the length of the largest “Y shape road”.

样例输入
2
5 5
1 2 9
5 1 2
2 5 3
3 4 6
3 1 2
3 3
1 2 1
2 3 3
3 1 2
样例输出
19
0
posted @ 2015-09-27 14:44  xgqfrms  阅读(89)  评论(0编辑  收藏  举报