405844: GYM102134 E Kth subtree

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Kth subtreetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Legends for tasks are different. There are long or short. There are boring or funny. There are understandable or not. You decide what this. Given a tree from n vertices. Also given are q queries. One query is a pair of numbers v and k. We choose v as a root and write down the sizes of the subtrees of each vertex of the tree in the nondecreasing order. The answer to the query is the k th number in this list.

Input

The first line of input contains two numbers - n and q (1 ≤ n ≤ 105, 1 ≤ q ≤ 105). Each of the following n - 1 rows contains a description of the edge of the tree - its ends ui and vi (1 ≤ ui, vi ≤ n) Each of the following q lines contains a description of the next query - the numbers vi and ki (1 ≤ vi, ki ≤ n)

Output

Output a response to each of the requests on a separate line.

ExampleInput
5 5
1 2
1 3
1 4
4 5
2 5
1 3
4 4
2 3
2 2
Output
5
1
3
2
1

加入题单

算法标签: