Matching on Tree Distance Graph
Time limit5sMemory limit952 MB
Given a weighted tree, find the maximum total weight of a matching of size k in the complete graph where edge weights are tree distances, for every k.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Tree, Divide and conquer
- Solved
- No attempts yet
Statement
This problem is dedicated to current ICPC champions, from one of the 2020 ICPC champions and, hopefully, the 2023 champions, to the 2021 champions and, hopefully, the 2022 champions, with love.
You are given an edge-weighted tree on vertices. Define as the sum of weights on the only simple path between and in . Consider a full weighted graph , where the weight of the edge is .
For every between and , calculate the maximum possible weight of a matching of size in graph . A matching of size is a set of edges such that no two edges in this set share a vertex.
Input
The first line contains one integer (), the size of the tree.
The next lines describe the edges of the tree. The -th of them contains three integers , , (, ), meaning that there is an edge with weight in .
It is guaranteed that the given edges form a tree.
Output
Print integers, the maximum weights of matchings of the corresponding sizes in .