Spicy Restaurant
题号:NC222764
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

There are hotpot restaurants numbered from to in Chengdu and the -th restaurant serves hotpots of a certain spicy value w_i. A higher spicy value indicates a hotter taste, while a lower spicy value is more gentle (still need to be very careful, though).

We can consider these restaurants as nodes on an undirected graph with edges. Now we have tourists who want to give the hotpots a try. Given the current positions of the tourists and the maximum spicy value they can bear, your task is to calculate the shortest distance between a tourist and the closest restaurant he can accept.

In this problem we define the distance of a path as the number of edges in the path.

输入描述:

There is only one test case in each test file.
The first line contains three integers , and () indicating the number of restaurants, the number of edges and the number of tourists.
The second line contains integers () where w_i indicates the spicy value of the -th restaurant.
For the following lines, the -th line contains two integers u_i and v_i (, ) indicating an edge connecting restaurant u_i and v_i.
For the following lines, the -th line contains two integers p_i and a_i (, ) indicating that the i-th tourist is currently at restaurant p_i and that the maximum spicy value he can accept is a_i.

输出描述:

Output  lines where the -th line contains one integer indicating the shortest distance between the -th tourist and the closest restaurant he can accept. If there is no such restaurant, output `-1' instead.
示例1

输入

复制
4 4 5
5 4 2 3
1 2
2 3
3 4
4 1
1 1
1 2
1 3
1 4
1 5

输出

复制
-1
2
1
1
0