#P4197. [ONTAK2010] Peaks

[ONTAK2010] Peaks

Description

In Bytemountains, there are nn peaks, and each peak has its height hih_i. Some pairs of peaks are connected by bidirectional roads; there are mm roads in total. Each road has a difficulty value, and a larger value means it is harder to traverse.

There are qq queries. For each query, starting from vertex vv, you may only traverse roads whose difficulty is less than or equal to xx. Among all peaks reachable this way, find the kk-th highest peak. If there is no such peak, output 1-1.

Input Format

The first line contains three integers n,m,qn, m, q. The second line contains nn integers, where the ii-th is hih_i.

The next mm lines each contain three integers a,b,ca, b, c, indicating there is a bidirectional road between aa and bb with difficulty cc.

The next qq lines each contain three integers v,x,kv, x, k, describing a query.

Output Format

For each query, output a single integer: the height of the kk-th highest reachable peak.

10 11 4
1 2 3 4 5 6 7 8 9 10
1 4 4
2 5 3
9 8 2
7 8 10
7 1 4
6 7 1
6 4 8
2 1 5
10 8 10
3 4 7
3 4 6
1 5 2
1 5 6
1 5 8
8 9 2
6
1
-1
8

Hint

Constraints
For 100%100\% of the testdata, 1v,kn1051 \le v, k \le n \le 10^5, 1m,q5×1051 \le m, q \le 5 \times 10^5, 1hi,c,x1091 \le h_i, c, x \le 10^9.

Translated by ChatGPT 5