#P14128. [SCCPC 2021] Spicy Restaurant

[SCCPC 2021] Spicy Restaurant

题目描述

There are nn hotpot restaurants numbered from 11 to nn in Chengdu and the ii-th restaurant serves hotpots of a certain spicy value wiw_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 nn restaurants as nodes on an undirected graph with mm edges. Now we have qq 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 nn, mm and qq (1n,m105,1q5×1051 \le n, m \le 10^5,1 \le q \le 5 \times 10^5) indicating the number of restaurants, the number of edges and the number of tourists.

The second line contains nn integers w1,w2,,wnw_1, w_2, \cdots, w_n (1wi1001 \le w_i \le 100) where wiw_i indicates the spicy value of the ii-th restaurant.

For the following mm lines, the ii-th line contains two integers uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n, uiviu_i \ne v_i) indicating an edge connecting restaurant uiu_i and viv_i.

For the following qq lines, the ii-th line contains two integers pip_i and aia_i (1pin1 \le p_i \le n, 1ai1001 \le a_i \le 100) indicating that the ii-th tourist is currently at restaurant pip_i and that the maximum spicy value he can accept is aia_i.

输出格式

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

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