- Time limit: 1.00 s
- Memory limit: 512 MB
You are given a tree with nodes. Some nodes contain a coin.
Your task is to answer queries of the form: what is the shortest length of a path from node to node that visits a node with a coin?
Input
The first line contains two integers and : the number of nodes and queries. The nodes are numbered .
The second line contains integers . If , node has a coin. If , node doesn't have a coin. You can assume at least one node has a coin.
Then there are lines describing the edges. Each line contains two integers and : there is an edge between nodes and .
Finally, there are lines describing the queries. Each line contains two integers and : the start and end nodes.
Output
Print integers: the answers to the queries.
Constraints
Example
Input:
5 4 1 0 0 1 0 2 4 2 3 1 3 3 5 1 5 3 2 4 4 5 5
Output:
2 3 0 4