Given a weighted tree with N vertices and N−1 edges. Let D(i,j) be the distance of the unique simple path from i to j in this tree (i.e., the path from i to j that will not visit any node more than once).
We construct a new directed graph with N vertices, for each pair of vertices (i,j) if i<j we add an edge from i to j with weight D(i,j).
Find the shortest path from 1 to all other vertices in the newly constructed graph.
Input
The first line contains one integer - N(2≤N≤8⋅104)
The (i+1)th(1≤i≤N−1) line contains three integers - ui,vi,wi(1≤ui<vi≤N,|wi|≤109), meaning there is an edge with cost wi between vertices ui and vi. These edges describe the original tree.
Output
Output N integers, the ith integer represents the shortest path from 1 to i.
1→2 with cost D(1,2)=−2
1→2→3 with cost D(1,2)+D(2,3)=−3
1→2→3→4 with cost D(1,2)+D(2,3)+D(3,4)=1
1→2→3→5 with cost D(1,2)+D(2,3)+D(3,5)=−10