#P8860. 动态图连通性

    ID: 9809 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心倍增洛谷原创O2优化最短路可持久化线段树洛谷月赛

动态图连通性

Problem Description

Given a directed graph with nn vertices and mm edges, initially there exists a path from 11 to nn.

You need to process qq queries. Each query gives a positive integer xx in [1,m][1,m]. If the xx-th edge in the original graph still exists, and after deleting the xx-th edge of the original graph from the current graph there is still a path from 11 to nn, then delete the xx-th edge of the original graph.

You need to report whether the xx-th edge was deleted in each query.

Note: once an edge is deleted in a query, it is deleted forever. That is, queries affect each other.

Input Format

The first line contains three positive integers n,m,qn,m,q, representing the number of vertices, the number of edges, and the number of queries in the directed graph.

The next mm lines each contain two positive integers ui,viu_i,v_i, meaning the ii-th edge goes from uiu_i to viv_i.

The next qq lines each contain one positive integer xx, with the same meaning as in the description.

Output Format

Output qq lines, each containing an integer 00 or 11.

If the xx-th edge was deleted in this query, output 11, otherwise output 00.

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

10 11 8
1 2
2 7
2 5
1 4
4 5
4 8
8 9
9 5
3 2
3 6
5 10
10
5
11
10
3
7
1
4

1
1
0
0
1
0
1
0

Hint

Sample Explanation

In the first sample:

Initially, the edge set of the graph is {(1,2),(2,3),(3,5),(2,4),(4,5),(5,1)}\{ (1,2),(2,3),(3,5),(2,4),(4,5),(5,1) \}.

If we delete the 11-st edge (1,2)(1,2) of the original graph, then there is no path from 11 to nn, so we cannot delete the 11-st edge.

If we delete the 22-nd edge (2,3)(2,3) of the original graph, then there exists a path 12451 \to 2 \to 4 \to 5, so we can delete the 22-nd edge, and the edge set becomes {(1,2),(3,5),(2,4),(4,5),(5,1)}\{ (1,2),(3,5),(2,4),(4,5),(5,1) \}.

If we delete the 33-rd edge (3,5)(3,5) of the original graph, then there exists a path 12451 \to 2 \to 4 \to 5, so we can delete the 33-rd edge, and the edge set becomes {(1,2),(2,4),(4,5),(5,1)}\{ (1,2),(2,4),(4,5),(5,1) \}.

If we delete the 44-th edge (2,4)(2,4) of the original graph, then there is no path from 11 to nn, so we cannot delete the 44-th edge.

If we delete the 55-th edge (4,5)(4,5) of the original graph, then there is no path from 11 to nn, so we cannot delete the 55-th edge.

Constraints

Test Point ID n,mn,m \leq qq \leq Special Constraints
121 \sim 2 10001000 None
363 \sim 6 50005000 2×1052 \times 10^5
787 \sim 8 2×1052 \times 10^5 It is guaranteed that among all queries, at most 11 edge is not deleted
9129 \sim 12 It is guaranteed that among all queries, at most 55 edges are not deleted
131613 \sim 16 Treating the directed graph as an undirected graph still gives the correct answer
172017 \sim 20 None

For all testdata, 1n,m,q2×1051 \leq n,m,q \leq 2 \times 10^5. The given graph has no multiple edges or self-loops, and there exists a path from 11 to nn.

The two provided large samples satisfy the constraints of test point 11 and test point 1313, respectively.

Translated by ChatGPT 5