#abc259f. F - Select Edges
F - Select Edges
Score : points
问题描述
给定一个包含 个顶点的树。对于每个 ,第 条边连接顶点 和顶点 ,且具有权重 。
考虑从这 条边中选择一些(可能无或全部)。这里,对于每个 ,至多可以选择与顶点 相邻的 条边。求所选边的最大可能总权重。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a tree with vertices. For each , the -th edge connects Vertex and Vertex and has a weight .
Consider choosing some of the edges (possibly none or all). Here, for each , one may choose at most edges incident to Vertex . Find the maximum possible total weight of the chosen edges.
Constraints
- is a non-negative integer not exceeding the degree of Vertex .
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
7
1 2 1 0 2 1 1
1 2 8
2 3 9
2 4 10
2 5 -3
5 6 8
5 7 3
Sample Output 1
28
If you choose the -st, -nd, -th, and -th edges, the total weight of those edges is . This is the maximum possible.
Sample Input 2
20
0 2 0 1 2 1 0 0 3 0 1 1 1 1 0 0 3 0 1 2
4 9 583
4 6 -431
5 9 325
17 6 131
17 2 -520
2 16 696
5 7 662
17 15 845
7 8 307
13 7 849
9 19 242
20 6 909
7 11 -775
17 18 557
14 20 95
18 10 646
4 3 -168
1 3 -917
11 12 30
Sample Output 2
2184
update @ 2024/3/10 11:00:02