Given a tree with N nodes connected by N−1 edges, rooted at node 1, each edge in the tree is assigned a value, which can be either positive, negative, or zero. Your task is to calculate, for each node, the smallest total sum of edge values that can be obtained on a simple path from that particular node to any leaf node in the tree.
Notes :
Input format
Output format
For each test case, print N integers in a new line, where the ith integer depicts the smallest total sum of edge values that can be obtained on a simple path from the ith node to any leaf node in the tree.
Constraints
1≤T≤1053≤N≤1061≤u,v≤N−109≤w≤109The sum of all values of N over all test cases doesn't exceed 106
The first line denotes T = 1.
For test case 1:
We are given:
Now, the simple paths, having the smallest total sum of edge values that can be obtained from each node to a leaf node, are:
Therefore, the answer is : 3 2 0 -2 0 0.