#C9744. Minimum Sum of Tree Nodes
Minimum Sum of Tree Nodes
Minimum Sum of Tree Nodes
You are given a tree with n nodes. Each node has an associated integer value. In each test case, you are allowed to perform any number of operations; however, note that the total sum of the node values remains unchanged regardless of the operations performed.
The task is to compute the minimum possible sum of the node values. Since any allowed operations do not affect the overall sum, the answer is simply the sum of all the given node values, i.e., \(\sum_{i=1}^{n} v_i\).
Note: The tree structure is provided for context, but it does not affect the answer.
inputFormat
The input is read from standard input and has the following format:
T n u1 v1 u2 v2 ... (n-1 lines representing edges) value_1 value_2 ... value_n ...
Here, the first line contains a single integer \(T\) denoting the number of test cases. For each test case:
- An integer \(n\) representing the number of nodes in the tree.
- The next \(n-1\) lines each contain two space-separated integers indicating an edge between two nodes (nodes are 1-indexed). For a tree with \(n=1\), there are no edge lines.
- The following line contains \(n\) space-separated integers representing the values of the nodes.
outputFormat
For each test case, output a single line containing a single integer: the minimum possible sum of node values.
Since the allowed operations do not change the sum, the answer is simply the sum of the given node values.
## sample2
3
1 2
1 3
1 5 3
5
1 2
1 3
1 4
4 5
1 2 3 4 5
9
15
</p>