#P15592. [ICPC 2020 Jakarta R] Cul-De-Sac Parades
[ICPC 2020 Jakarta R] Cul-De-Sac Parades
题目描述
Treantis is a wonderful town with junctions (numbered from to ) that are connected by exactly roads such that one can go from one junction to any other junction using a sequence of roads. Such a special structure causes Treantis to have some junctions in which each of them is only connected to exactly one other junction; such a junction is known as a cul-de-sac (or a dead-end junction) in Treantis.
To live up the town, the mayor of Treantis decides to carry out a festival in Treantis with glamorous parades. Due to some superstition in Treantis, there are two constraints that should be fulfilled when designing the routes for the parades.
- Each parade should march starting from a cul-de-sac, ending at another cul-de-sac, and never passing the same road more than once.
- Any two parades should not share a common road on their paths; on the other hand, sharing the same junction is not an issue.
The mayor has estimated that if a parade passes a road connecting junction and junction , then the citizen happiness will be increased by .
Your task in this problem is to help the mayor to calculate the maximum happiness that can be obtained by carefully designing the parades while satisfying the two constraints mentioned above.
For example, let and the town structure is as shown in the following figure.
:::align{center}
:::
As we can see, there are cul-de-sacs and their numbers are . In this example, the maximum happiness can be obtained by running parades of the following routes.
- with a happiness of .
- with a happiness of .
- with a happiness of .
Observe that all those parades start and end at a cul-de-sac and no two parades share the same road. The total happiness of those parades is . There are no parades that yield a happiness of more than in this example.
输入格式
Input begins with a line containing an integer: () representing the number of junctions in Treantis. The next lines each contains three integers: (; ) representing a road and its increment in happiness if this road is passed by a parade, respectively. It is guaranteed that one can go from one junction to any other junction using a sequence of roads.
输出格式
Output in a line an integer representing the maximum happiness that can be obtained by carefully designing the parades while satisfying all the constraints.
10
1 5 10
2 5 20
3 6 20
4 7 40
5 6 50
5 8 30
6 7 10
6 9 20
7 10 40
210
7
1 2 10
1 3 5
2 4 15
2 5 20
3 6 12
3 7 13
60
提示
Explanation for the sample input/output #1
This is the example from the problem description.