353. Sum at One Depth
Print the total of the values at depth k, counting the root as depth 1.
Print 0 if the tree is shallower than k.
Problem 335 printed every row's total; this one asks for a single row, which
means you can stop descending as soon as the depth passes k.
The empty answer is 0, which is the natural total of nothing and needs no special case.
Constraints - `1 ≤ n ≤ 100000` - `1 ≤ k ≤ 100000` - `-1000000000 ≤ value ≤ 1000000000` - The input always forms a valid tree rooted at node 1.
Input
The first line contains two integers n and k.
The second line contains n values, where node i holds the ith value.
Each of the next n lines contains the left and right child of node i,
using 0 for no child. Node 1 is the root at depth 1.
Output
Print one integer, the total of the values at depth k, or 0 if none exist.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.