You are given a directed acyclic graph of nodes numbered from to and you need to perform queries on it. Node has a value of , and every other node has a value of . Every node only has 1 child. Find the sum of values of a node and all of its children.
The first line will contain the integer , the number of nodes and the number of queries.
The next lines describes which nodes are connected. The line contains the integers , where is the node's child.
The next lines contains an integer , the node to query.
For every query, print the sum of values of the node and all of its children.
5 5 1 0 2 0 4 1 8 2 16 3 1 2 3 4 5
1 2 5 10 21
Subtask 1 [30%]
Subtask 2 [70%]
No further constraints.