Simple Path

0

0 votes
Hard
Problem

You are given a tree of N nodes rooted at node 1.
You have to answer Q queries. In each query, you will be given two numbers V and X. You have to tell how many node U are there in the path from the root to node V (U!=V) such that A[U] *A[V] <= X.

INPUT:

The first line of input contains a number N denoting a total number of nodes.
The second line contains N integers where ith integer denotes the value of the node i ie. A[i].

Next N-1 lines contain U and V denoting edges between node U and V.

Next line contains an integer Q denoting the number of queries.
Next Q lines contains two integers V and X.

OUTPUT:
Output Q lines where the ith line should be the answer for the ith query.

CONSTRAINTS:

1N,Q105

1X,A[i]106

1U,VN

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?