#P15922. [TOPC 2023] Finding Bridges

[TOPC 2023] Finding Bridges

题目描述

An undirected graph is a fundamental concept in graph theory, a branch of mathematics and computer science. It is a data structure that represents a set of vertices connected by edges that have no direction. In other words, in an undirected graph, if there is an edge from vertex uu to vertex vv, there is also an edge from vertex vv to vertex uu. We use a two-element set {A,B}\{A, B\} to represent such undirected edge. An undirected graph is simple if there is at most one edge between any pair of vertices.

In graph theory, a connected component is a group of vertices and edges within a graph where you can travel from any vertex to any other vertex by following a sequence of edges. A bridge is an edge in an undirected graph that, if removed, increases the number of connected components in the graph.

Bridges are essential concepts in graph analysis and have practical applications in network design, fault tolerance, and connectivity analysis. They are often used to identify vulnerable points in a network where the removal of a single edge could lead to the isolation of certain components or the disruption of connectivity. Identifying bridges in a graph can be done using various algorithms which can detect these crucial edges and help analyze the robustness and structure of a network or system.

You have a simple undirected graph whose vertices and edges are V={1,2,,n}V = \{1, 2, \dots, n\} and E={{u1,v1},,{um,vm}}E = \{\{u_1, v_1\}, \dots, \{u_m, v_m\}\}. Your friend, Flora, ask you to sequentially remove edges e1,e2,,eqe_1, e_2, \dots, e_q from your graph and report the number of bridges left in the graph after each removal. Please write a program to generate the report.

输入格式

The first line contains three space-separated non-negative integers nn, mm and qq. nn is the number of vertices of the graph. mm is the number of edges of the graph. qq is the number of edges to be removed. The ii-th of the following mm lines contains two space-separated positive integers, uiu_i and viv_i, indicating the ii-th element of EE. Then qq lines follows. The jj-th of them contains two space-separated positive integers, xjx_j and yjy_j, indicating the jj-th removed edge ej={xj,yj}e_j = \{x_j, y_j\}.

输出格式

Output qq lines. The kk-th line should contain an integer bkb_k indicating the number of bridges in the graph after removing kk edges.

5 7 5
1 2
1 3
1 4
1 5
2 3
3 4
4 5
3 4
2 3
1 2
4 5
1 4
0
2
1
3
2

提示

  • 1<n2000001 < n \le 200000
  • 1mmin(200000,(n2))1 \le m \le \min\left(200000, \binom{n}{2}\right)
  • 1qm1 \le q \le m
  • There are two ways to represent an edge {u,v}\{u, v\}: “u vu\ v” and “v uv\ u”.
  • {xi,yi}\{x_i, y_i\} must be an edge in EE.
  • No edge will be removed twice.