#P9047. [PA 2021] Poborcy podatkowi
[PA 2021] Poborcy podatkowi
Problem Description
Given a tree with vertices, you may choose several pairwise disjoint paths of length (meaning edges) (you may also choose none).
For a chosen set of paths, the profit is the sum of edge weights in the union of all chosen paths. Find the maximum profit.
Input Format
The first line contains an integer .
The next lines each contain three integers , describing an edge in the tree with weight .
Output Format
Output one line with one integer, the required value.
19
1 2 1
2 3 2
3 4 -1
4 5 -1
5 6 2
6 7 11
7 8 12
8 9 13
9 10 14
11 12 3
12 13 0
13 14 0
14 15 0
15 16 1
16 4 0
4 17 0
17 18 0
18 19 2
57
6
1 2 2
2 3 -1
3 4 -1
4 5 -1
5 6 2
0
Hint
Explanation of Sample #1
One optimal solution is to choose the paths , , , .
Explanation of Sample #2
Since the weight of every length path is negative, choosing none is optimal.
Constraints
For of the testdata, , and .
Translated by ChatGPT 5