Under construction

Still being built. Things may change

Matching on Tree Distance Graph

Time limit5sMemory limit952 MB

Summary
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 TT on nn vertices. Define duvd_{uv} as the sum of weights on the only simple path between uu and vv in TT. Consider a full weighted graph GG, where the weight of the edge (u,v)(u, v) is duvd_{uv}.

For every kk between 11 and ⌊n/2⌋\lfloor n/2 \rfloor, calculate the maximum possible weight of a matching of size kk in graph GG. A matching of size kk is a set of kk edges such that no two edges in this set share a vertex.

Input

The first line contains one integer nn (2≤n≤100 0002 \le n \le 100\,000), the size of the tree.

The next n−1n-1 lines describe the edges of the tree. The ii-th of them contains three integers uiu_i, viv_i, wiw_i (1≤ui,vi≤n1 \le u_i, v_i \le n, 1≤wi≤1081 \le w_i \le 10^8), meaning that there is an edge (ui,vi)(u_i, v_i) with weight wiw_i in TT.

It is guaranteed that the given edges form a tree.

Output

Print ⌊n/2⌋\lfloor n/2 \rfloor integers, the maximum weights of matchings of the corresponding sizes in GG.

Examples1

  1. Example 1

    Input
    7
    1 3 99
    2 3 82
    3 4 4
    4 5 43
    5 6 5
    4 7 3
    
    Expected output
    181 280 287