#c22604. 路径上的最小点权
路径上的最小点权
Minimum Node Weight on a Path
Problem Description
You are given a tree with nodes, numbered from to , each with a node weight .
There are queries. Each query reads two integers and asks: what is the minimum node weight on the path from node to node ?
Input Format
The first line contains two integers , the number of vertices and the number of queries.
The second line contains integers .
The following lines each contain two integers , meaning there is an edge between node and node .
The following lines each contain two integers , representing one query.
Output Format
For each query, output one line containing an integer: the answer.
Sample Input
3 3
1 2 3
1 2
2 3
1 2
1 3
2 3
Sample Output
1
1
2
Constraints
For of the data, $1 \leq n, q \leq 10^5, 1 \leq a_i \leq 10^5, 1 \leq u, v \leq n, u \neq v$, and the input is guaranteed to form a tree.