#P3177. [HAOI2015] 树上染色
[HAOI2015] 树上染色
Description
There is a tree with nodes, and each edge has a weight. You are given a positive integer in . You need to choose nodes and color them black, and color the remaining nodes white. After coloring all nodes, you gain a profit equal to the sum of pairwise distances among black nodes plus the sum of pairwise distances among white nodes. What is the maximum possible profit?
Input Format
The first line contains two integers .
Lines to each contain three positive integers , indicating that there is an edge of length in the tree. The input guarantees that all nodes are connected.
Output Format
Output a single positive integer, the maximum profit.
3 1
1 2 1
1 3 2
3
Hint
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号