Virat and Anushka
All submissions for this problem are available.###Problem Statement: Keteki Country has $N$ connected cities (numbered 1,2,3,...,N) and $N-1$ bidirectional roads.A road from $X$ to $Y$ means that we can travel from City $X$ to City $Y$ and vice-versa.City 1 is the capital of Keteki Country.As the distance of a city from the Capital City increases,the quantity of vegetables increases. Kohli takes Anushka for a tour to Keteki Country.As we all know that Anushka recently turned into a vegetarian,she can go to city y from city x,only if city y has more vegetables than the current city.Also,she would only visit cities which are at a distance of $D$ from the current city. There are $Q$ Queries, each query has the current city $Ci$ and Distance $Di$ .Kohli wants to know the maximum number of cities,he can take her. ###Input: First line of the input contains 2 space-separated integers, $N$ and $Q$ denoting the number of cities and the number of queries. It is followed by $N-1$ lines with each line containing two space separated integers $x$ and $y$, indicating a road between city x and city y. It is followed by $Q$ lines, where each line has two space separated integers $C$ and $D$,denoting the current city of the couple and the distance $D$ respectively. ###Output: For each query, output the maximum number of cities the couple can visit. ###Constraints: $1 \leq N,Q \leq 10^5$ $1 \leq C,D \leq N$ ###Sample Input: 3 2 1 2 1 3 1 1 2 1 ###Sample Output: 2 0 ###Explanation: $1$ / \ $2$ $3$ Query1: Cities 2,3 are at a distance of 1 from City 1 and has more vegetables than City 1 . Query2:There are no cities at a distance of 1 from City 2 which has more vegetables than City 2.
|Tags||gabilash, keteki, kpm22019|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions