首页 > 其他 > 详细

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

时间:2015-09-27 14:53:18      阅读:232      评论:0      收藏:0      [点我收藏+]

#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

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

原文:http://www.cnblogs.com/xgqfrms/p/4842228.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!