ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
#1235 : New Teaching Buildings
描述
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
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/4842228.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)