You are given a tree. Each of vertices has time, when it is active (from to inclusive). You are given queries of two kinds:
, asking how many active nodes are on path between and in time .
, asking how many active nodes are in the subtree of in time .
The tree will be rooted at node number 0.
The first line of input will contain and (), the size of tree and number of queries.
The next line will contain numbers (, the start time of each node).
The next line will contain numbers (, end time of each node).
Both start times/end times will be in range from to (and start time will never be after end).
The next lines will contain two integers and (), the edges of the tree.
The last will be in form described above. Here both , will be in range from 0 to and from range to .
For each query, output the number of active nodes in given time.
Input | Output |
---|---|
5 6 1 2 3 4 5 6 7 8 9 10 0 1 0 2 2 3 2 4 2 3 0 2 11 0 2 6 0 1 10 2 4 1 5 3 4 1 3 4 3 | 3 0 5 1 3 1 |