#C9133. Sum of Deepest Nodes

    ID: 53193 Type: Default 1000ms 256MiB

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 integers u and v which represent an edge between nodes u and v.

outputFormat

Output a single integer which is the sum of the node values at the deepest level of the tree.

## sample
1
1