#P11191. 「KDOI-10」超级演出
「KDOI-10」超级演出
Description
Meguru has prepared a super show!
The stage and the waiting rooms can be seen as a directed acyclic graph (DAG) consisting of vertices and edges.
The stage is at vertex , and the rest vertices are all waiting rooms. It is guaranteed that each vertex has at least one path to vertex . For each waiting room, there is a troupe in it initially.
Meguru can send an enter command to a waiting room :
- If the troupe in this room has not come to the stage yet, and there exists a path from to such that there are no troupe waiting for entrance, then the troupe in waiting room will come to the stage and subsequently exit. Note that a troupe will not return to the waiting room after the exit.
- Otherwise, this command is considered as inoperative.
Meguru has a command sequence and queries. In each query, an interval is given, and Meguru asks you that, if she sends the enter command to waiting room successively, how many troupes are still in the waiting room.
Note that each query is independent, i.e., before each query, there is a troupe in each waiting room.
Input Format
The first line of the input contains a single integer — the id of the test. represents that this is a sample test.
The second line contains four integers , , , and — the number of vertices, the number of edges, the length of the command sequence, and the number of queries.
Then lines follow, each containing two integer and — there is an edge connecting and . It is guaranteed that there are no self-loops or multiple-edges.
The next line contains integers — the command sequence.
Then lines follow, each containing two integers and — the interval in the query.
Output Format
Print lines, each line containing a single integer — the answer to the query.
0
5 5 5 4
2 1
3 1
5 1
4 2
4 3
2 4 4 3 5
1 2
1 5
3 5
2 3
2
0
2
4
Hint
Sample 1 Explanation

-
In the query , :
- For the command , comes to the stage by ;
- For the command , comes to the stage by .
Troupes are left, so output .
-
In the query , :
- For the command , there does not exist a valid path, so this command is inoperative.
- For the command , there does not exist a valid path, so this command is inoperative.
Troupes are left, so output .
Sample 2
See show/show2.in and show/show2.ans in the attachments.
This sample satisfies the constraints of test .
Sample 3
See show/show3.in and show/show3.ans in the attachments.
This sample satisfies the constraints of test .
Sample 4
See show/show4.in and show/show4.ans in the attachments.
This sample satisfies the constraints of test .
Sample 5
See show/show5.in and show/show5.ans in the attachments.
This sample satisfies the constraints of test .
Sample 6
See show/show6.in and show/show6.ans in the attachments.
This sample satisfies the constraints of test .
Constraints
For all the tests, it is guaranteed that:
- ;
- ;
- , and all -s are distinct;
- For each , ;
- For each query, ;
- The input forms a DAG, and each vertex has at least one path to vertex .
| Test Id | Special Properties | ||
|---|---|---|---|
| - | |||
| A | |||
| - | |||
| A | |||
| BC | |||
| C | |||
| BD | |||
| D | |||
| B | |||
| - |
- Property A: The graph is degenerated into an inward-directed tree, i.e. each vertex except vertex has out-degree ;
- Property B: For each query, ;
- Property C: For each , ;
- Property D: The in-degree and out-degree of each vertex does not exceed , respectively.
京公网安备 11011102002149号