You are given a tree comprising \(n\) nodes numbered from \(1\) to \(n\). You have to answer \(q\) queries each consisting of three numbers – \(r\), \(d_1\) and \(d_2\).
For each query, print the number of nodes whose depth is between \(d_1\) and \(d_2\) (inclusive) if the tree is rooted at node \(r\). The depth of root node itself is \(0\), the depth of all its children is \(1\) and so on.
Input format
First line: \(n\) (the number of nodes) and \(q\) (the number of queries)
Next \(n-1\) lines: \(u_i\) and \(v_i\)denoting an edge between the nodes \(u_i\) and \(v_i\).The next \(q\) lines consist of three integers \(r\) , \(d_1\) and \(d_2\) .
Output format
For each query, print the answer in a new line.
input Constraints
For node 1, there are 4 nodes whose depth is between 0 and 2 (1,2,3 and 4). For node 2 there are 3 nodes whose depth is between 0 and 1 (1,2 and 4).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor