406260: GYM102331 J Jiry Matchings

Memory Limit:0 MB Time Limit:6 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Jiry Matchingstime limit per test6 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

Ruyi Ji has a tree where the vertices are numbered by integers from $$$1$$$ to $$$n$$$ and each edge has a weight.

For each $$$k \leq (n-1)$$$, he asked you to find the largest total weight of a matching with $$$k$$$ edges if it exists.

Input

The first line of input contains one integer $$$n$$$: the number of vertices in the tree ($$$2 \leq n \leq 200\,000$$$).

Each of the next $$$n-1$$$ lines contains three integers $$$u_i$$$, $$$v_i$$$, $$$w_i$$$, describing an edge from $$$u_i$$$ to $$$v_i$$$ with weight $$$w_i$$$ in the tree ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$, $$$-10^9 \leq w_i \leq 10^9$$$).

It is guaranteed that the given graph is a tree.

Output

Output $$$n - 1$$$ integers: the largest weights of the matchings with $$$1, 2, \ldots, n - 1$$$ edges. If there is no such matching for the current $$$k$$$, print "?" instead.

ExamplesInput
5
1 2 3
2 3 5
2 4 4
3 5 2
Output
5 6 ? ? 
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
Output
5 10 15 10 ? ? ? ? ? 
Input
2
1 2 35
Output
35 
Note

In the first sample, with $$$k=1$$$ you should take edge $$$(2, 3)$$$ with weight $$$5$$$. And with $$$k=2$$$ you should take two edges, $$$(2, 4)$$$ and $$$(3, 5)$$$, with total weight $$$6$$$. There are no matchings with a greater number of edges.

加入题单

算法标签: