ACM-ICPC International College Student Program Design Competition Beijing (2015) online race

Source: Internet
Author: User

#1235: New Teaching Buildings time limit:2000msSingle Point time limit:2000msMemory Limit:256MBDescribe

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

The school could is seen as a connected graph with n vertices and m edges, in which every vertex belongs to at most a sing Le cycle (the one consists of a sequence of vertices starting and ending at the same vertex, with each of the consecutive vert ICES in the sequence adjacent to all other in the graph and no repetitions of vertices other than the repetition of start ing 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 has any common Verti CES except it. As we know, a simple road is a finite sequence of edges which connect a sequence of vertices which be all distinct from O Ne another. The longest one is exactly the one contains the largest length of roads.

Can you help him?

Input

There is no more than test cases, and the most cases is very small.

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

The first line of all test case contains-integers, N, m, which is the number of vertices and the number of edges. All vertices is numbered from 1 to N.

The next m lines, each line consists of three integers, u, V, W, which means there are an undirected edge between U and V, And its length is W.

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

Output

For each test case, output the length of the largest "Y shape Road".

Sample input
25 51 2 95 1 22 5 33 4 63 1 23 31 2 12 3 33 1 2
Sample output
190

ACM-ICPC International College Student Program Design Competition Beijing (2015) online race

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.