luogu#P7834. [ONTAK2010] Peaks 加强版
[ONTAK2010] Peaks 加强版
Background
Original problem link: P4197 Peaks.
Problem Description
Given an undirected graph with vertices and edges. The weight of vertex is , and each edge has an edge weight.
There are queries. Each query gives three integers . Starting from , you may only traverse edges with edge weight . Among all vertices that can be reached, output the vertex weight that is the -th largest. If it does not exist, output .
This problem is forced online. That is: for each query, the input is , then $u = (u' \operatorname{xor} \text{lastans}) \bmod n + 1$, and is decrypted in the same way, and .
Input Format
The first line contains three integers .
The second line contains integers .
The next lines each contain three integers , representing the two endpoints of an edge and its weight.
The next lines each contain three integers .
Note: for the first query and for cases with no solution, .
Output Format
For each query, output one line with one integer, representing the required value.
10 11 3
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
0 5 5
1 6 8
7 8 1
1
-1
8
Hint
For of the testdata, , , , , .
Translated by ChatGPT 5