Does your thesis have practical applications?
_____________________________________________________
Popular question
Legend
Sergey is nearing the completion of his thesis. Since December, the topic has remained unchanged: "Dynamic 2-Edge-Connectivity Problem." An algorithm has been developed, tested, and its O(K \log K) complexity has been proven. Now, only the chapter on practical applications remains to be written.
But what practical use could there be for the Dynamic 2-Edge-Connectivity Problem? It's a challenging question—perhaps even harder than the problem itself. However, the thesis must be defended, so an answer is urgently needed.
Thus, here's a practical application: you can make a contest problem based on this topic!
Problem
You are given an undirected graph with up to 10^5 vertices. Initially, the graph contains no edges. You will process queries of the form ADD and DEL —adding or removing the edge between vertices and .
At any moment, you must determine how many bridges there are in the current graph.
There are never multiple edges or loops in the graph at any time.
If a "delete an edge" command is issued, the corresponding edge is guaranteed to exist in the graph at that moment.
Hints
A thesis is called a "thesis" precisely because it cannot be written in just hours. So here are hints:
Add and remove edges—make an edge "alive" for a certain time interval.
Use the "Divide and Conquer" approach.
Compress biconnected components.
Even after compressing biconnected components, if the number of queries is small, the graph can still be further reduced.
An O(K \log K) solution exists.
The first line contains two integers and : the number of vertices and the number of queries, respectively (1 \leq N \leq 10^5, 1 \leq K \leq 10^5).
The next lines each contain a query in the following format. Each query begins with the word ADD or DEL for adding or removing an edge, respectively. After this word follow two integers and specifying the endpoints of the edge (1 \leq a, b \leq N, a \neq b).
After each query, output a single integer: the current number of bridges in the graph.
Example 1