#P4197. [ONTAK2010] Peaks
[ONTAK2010] Peaks
Description
In Bytemountains, there are peaks, and each peak has its height . Some pairs of peaks are connected by bidirectional roads; there are roads in total. Each road has a difficulty value, and a larger value means it is harder to traverse.
There are queries. For each query, starting from vertex , you may only traverse roads whose difficulty is less than or equal to . Among all peaks reachable this way, find the -th highest peak. If there is no such peak, output .
Input Format
The first line contains three integers . The second line contains integers, where the -th is .
The next lines each contain three integers , indicating there is a bidirectional road between and with difficulty .
The next lines each contain three integers , describing a query.
Output Format
For each query, output a single integer: the height of the -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 of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号