Under construction

Still being built. Things may change

Jiry Matchings

Time limit6sMemory limit512 MB

Summary
Given a weighted tree, find the maximum total weight of a matching with k edges for each k from 1 to n-1, or print ? if none exists.
Level

Hard8 of 10

Topics
Tree, Dynamic programming, Heap
Solved
No attempts yet

Problem

Ruyi Ji has a tree with nn vertices, numbered from 11 to nn. Each edge has a weight.

For each k≤n−1k \le n - 1, find the largest total weight of a matching with kk edges. If no matching with kk edges exists, print "?" instead.

Input

The first line contains one integer nn (2≤n≤2000002 \le n \le 200000), the number of vertices.

Each of the next n−1n - 1 lines contains three integers uiu_i, viv_i, wiw_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i, −109≤wi≤109-10^9 \le w_i \le 10^9), describing an edge between uiu_i and viv_i with weight wiw_i. The given graph is guaranteed to be a tree.

Output

Print n−1n - 1 integers: the largest total weight of a matching with 1,2,…,n−11, 2, \ldots, n - 1 edges. Print "?" for each kk that has no such matching.

Hint

In the first sample, with k=1k = 1, take the edge (2,3)(2, 3) with weight 55. With k=2k = 2, take the two edges (2,4)(2, 4) and (3,5)(3, 5), for a total weight of 66. No matching has more edges than that.

Examples3

  1. Example 1

    Input
    5
    1 2 3
    2 3 5
    2 4 4
    3 5 2
    
    Expected output
    5 6 ? ?
    
  2. Example 2

    Input
    10
    2 8 -5
    5 10 5
    3 4 -5
    1 6 5
    3 9 5
    1 7 -3
    4 8 -5
    10 8 -5
    1 8 -3
    
    Expected output
    5 10 15 10 ? ? ? ? ?
    
  3. Example 3

    Input
    2
    1 2 35
    
    Expected output
    35