#P12626. [NAC 2025] Most Scenic Cycle
[NAC 2025] Most Scenic Cycle
题目描述
The government of the Independent Country of Problem Creators (ICPC) finally saved enough money to construct high speed rail infrastructure. The new rail system has stations and bidirectional direct railway lines that each connect two stations together. The head of ICPC Rail Infrastructure Planning, Skib E. Dee, has seen enough programming problems about tree-topology transportation networks in other countries to know that such a network would be a recipe for disaster: a single broken railway line would split the network into disconnected pieces and disrupt travel for days. Instead, Dee decided that the ICPC rail network will be robustly connected: every pair of stations , must be connected by at least two paths which do not share any direct railway lines, and do not share any railway stations other than and themselves.
Of course, ICPC cannot afford to build too many redundant railway lines. To balance efficiency and resiliency, Dee has also designed the network to be regionally connected. A cycle is a non-empty path from a station to itself which doesn't repeat any railway station (apart from the first station, which must repeat exactly once as the last station of the cycle). In order for the network to be regionally connected, there must exist a set of regional cycles satisfying three properties:
- every direct railway line in the transportation network belongs to at least one regional cycle;
- if two regional cycles share any direct railway lines, then all railway lines and stations shared by those cycles lie along a connected path;
- for each subset of , at most pairs of regional cycles in share any direct railway lines.
To promote the new high speed rail, Dee needs to create a timelapse video of a train travelling around some cycle in the railway network. Each direct railway line has a (possibly negative) scenic value representing how nice the view out the train window is along that line. Dee wants to send the train around whichever cycle maximizes the sum of scenic values of the direct railway lines on the cycle---compute this maximum possible sum. (The most scenic cycle that Dee is looking for does not have to be a regional cycle.) In order to ensure this cycle is not boring, it must traverse at least two direct railway lines, and must not repeat any railway station (apart from the first station, which must repeat exactly once as the last station of the cycle).
输入格式
The first line of input contains two space-separated integers () and (), the number of stations and direct railway lines in the rail network, respectively.
The next lines of input describe the direct railway lines. Each line contains three space-separated integers , , and (; ), signifying that a direct railway line exists between stations and with scenic value . No direct railway line connects a station to itself, but multiple direct railway lines might exist between the same two stations. It is guaranteed that the input graph will be both robustly connected and regionally connected.
输出格式
Print the sum of scenic values around the cycle in the railway network that maximizes this sum.
6 9
1 2 9
2 3 9
3 4 9
3 4 -9
4 1 9
1 5 1
5 6 1
6 2 1
3 4 8
36
5 7
1 2 1
2 3 -2
3 4 3
4 5 6
5 1 4
5 3 2
2 5 9
16
提示
For the railway network in Sample Input 2, one possible choice for the regional cycles in are , , and (pictured on the left). The most scenic cycle (pictured on the right, in blue) has a scenic value sum of .