#P7520. [省选联考 2021 A 卷] 支配

[省选联考 2021 A 卷] 支配

Description

Given a directed graph GG with nn vertices and mm edges, whose vertices are numbered from 11 to nn.

For any two vertices u,vu, v, if every path from vertex 11 to vertex vv must pass through vertex uu, then vertex uu is said to dominate vertex vv. In particular, every vertex dominates itself.

For any vertex vv, the set of vertices in the graph that dominate vertex vv is called the dominator set of vv, denoted by DvD_v.

Now there are qq independent queries. Each query gives a directed edge. You need to answer: after adding this edge to graph GG, for how many vertices does their dominator set change.

Input Format

The first line contains three integers n,m,qn, m, q, representing the number of vertices, the number of edges, and the number of queries, respectively.
The next mm lines each contain two integers xi,yix_i, y_i, representing a directed edge from xix_i to yiy_i.
The next qq lines each contain two integers si,tis_i, t_i, representing that in this query, an edge from sis_i to tit_i is added.

The data guarantees that in the given graph GG, all other vertices are reachable from vertex 11, and the graph contains no multiple edges or self-loops.

Output Format

For each query, output one line with one integer, representing the answer.

6 6 3
1 2
1 3
3 4
4 5
2 6
4 1
5 6
3 2
2 4

1
0
2

见附件中的 dominator/dominator2.in。
见附件中的 dominator/dominator2.ans。
见附件中的 dominator/dominator3.in。
见附件中的 dominator/dominator3.ans。

Hint

【Sample #1 Explanation】

For the original graph, the dominator sets of the six vertices are: D1={1}D_1 = \{ 1 \}, D2={1,2}D_2 = \{ 1, 2 \}, D3={1,3}D_3 = \{ 1, 3 \}, D4={1,3,4}D_4 =\{ 1, 3, 4 \}, D5={1,3,4,5}D_5 = \{ 1, 3, 4, 5 \}, D6={1,2,6}D_6 = \{ 1, 2, 6 \}.

After adding 565 \to 6, D6={1,6}D_6 = \{ 1, 6 \}, and the dominator sets of other vertices remain unchanged.

After adding 323 \to 2, no vertex’s dominator set changes.

After adding 242 \to 4, D4={1,4}D_4 = \{ 1, 4 \}, D5={1,4,5}D_5 = \{ 1, 4, 5 \}, and the dominator sets of other vertices remain unchanged.


【Constraints】

For all testdata: 1n3×1031 \le n \le 3 \times {10}^3, 1m2×n1 \le m \le 2 \times n, 1q2×1041 \le q \le 2 \times {10}^4.

The detailed limits for each test point are shown in the table below:

Test Point ID nn \le Special Property
121 \sim 2 1010 None
363 \sim 6 100100 q100q \le 100
797 \sim 9 10001000 m=n1m = n - 1
101510 \sim 15 q2000q \le 2000
162016 \sim 20 30003000 None

Translated by ChatGPT 5