#C9133. Sum of Deepest Nodes
Sum of Deepest Nodes
Sum of Deepest Nodes
You are given a tree with n nodes, numbered from 1 to n. The tree is represented as an edge list and is rooted at node 1. Your task is to compute the sum of the values (labels) of all nodes on the deepest level of the tree.
Let the set of nodes at the deepest level be \( L \). Then the answer is given by:
[ \text{Answer} = \sum_{v \in L} v ]
You should read the tree from standard input and output the result to standard output.
inputFormat
The input is given from standard input in the following format:
n u1 v1 u2 v2 ... un-1 vn-1
Where:
n
(1 ≤ n) is the number of nodes in the tree.- Each of the next
n-1
lines contains two integersu
andv
which represent an edge between nodesu
andv
.
outputFormat
Output a single integer which is the sum of the node values at the deepest level of the tree.
## sample1
1