#P6592. [YsOI2020] 幼儿园
[YsOI2020] 幼儿园
Description
Ysuperman loves taking walks in their kindergarten. To make walking easier, they model the kindergarten as a directed graph with vertices and edges. After walking a lot, they assign each edge an unparalleled closeness value: . A larger value means a closer relationship. They also assign each vertex an unparalleled label: , where represents the kindergarten gate. However, vertices have no closeness value.
Over the next days, Ysuperman has one walking plan each day. Specifically, they want to start from vertex , use only edges whose closeness values lie in the interval , and reach the gate vertex . Along the way, the closeness values of the edges used must be strictly decreasing; otherwise, due to their OCD, they cannot go home.
Ysuperman is completely confused by the draft they just drew. They realize they cannot plan so many valid routes, so they ask you for help. For each day’s plan, output 1 if it is feasible, otherwise output 0.
Of course, sometimes Ysuperman is in a hurry and needs you to reply immediately; sometimes they can wait and ask all questions first, then wait for your reply.
Input Format
The first line contains four integers , representing the number of vertices, the number of edges, the number of Ysuperman’s plans, and Ysuperman’s level of urgency. Here will be used later in the input.
Then lines follow. The -th of these lines contains two integers , indicating that there is a directed edge from vertex to vertex in the kindergarten, and its closeness value is .
Then lines follow. The -th of these lines contains three integers , representing Ysuperman’s -th plan.
If , then are in plaintext and can be used directly.
If , then are encrypted and you need to decrypt them. The decryption is: let be the sum of the outputs of all previous queries (if there were no previous queries, then ). You need to XOR with .
Output Format
Output lines. Each line is either 1 or 0. The number on the -th line indicates whether the -th plan is feasible.
5 7 5 0
3 2
1 2
4 3
5 4
3 1
5 3
5 1
3 1 4
1 2 2
5 5 6
4 5 7
2 1 7
0
1
1
0
0
5 12 10 0
4 2
4 2
5 3
3 3
1 5
1 4
4 4
2 4
5 3
1 5
2 2
4 1
4 3 5
4 2 3
1 4 5
3 1 8
3 1 4
3 5 5
2 1 12
4 10 12
2 5 5
1 1 3
0
0
1
0
0
0
0
1
0
1
5 12 10 1
4 2
4 2
5 3
3 3
1 5
1 4
4 4
2 4
5 3
1 5
2 2
4 1
4 3 5
4 2 3
1 4 5
2 0 9
2 0 5
2 4 4
3 0 13
5 11 13
0 7 7
3 3 1
0
0
1
0
0
0
0
1
0
1
Hint
Sample Explanation
Sample Explanation

For the -nd plan, Ysuperman is already at the gate, so the plan is feasible.
For the -rd plan, Ysuperman can only take the path $5 \overset{6}{\rightarrow}3 \overset{5}{\rightarrow} 1$. (The number above each arrow is the closeness value of the edge.)
All other plans are infeasible.
Sample Explanation
Sample 3 is Sample 2 after encryption.
Constraints
This problem uses bundled testdata.
| Special property | Score | ||||
|---|---|---|---|---|---|
| / | |||||
| / | |||||
For of the testdata, $1 \le n \le 10^5,1 \le m \le 2\cdot10^5,0 \le k \le 2\cdot10^5$.
.
After decryption, are guaranteed to satisfy .
Hint
There may be multiple edges and self-loops, and the graph is not guaranteed to be connected.
Translated by ChatGPT 5
京公网安备 11011102002149号