Link Cut Digraph
Time limit3sMemory limit512 MB
Edges of a directed graph arrive one at a time, and after each insertion the task is to count pairs of vertices that are mutually reachable. Up to 1e5 vertices and 2.5e5 edges.
- Level
Hard10 of 10
- Topics
- Graph, Divide and conquer, Union-find
- Solved
- No attempts yet
Problem
You are given a graph with vertices and no edges at first. There are operations. Each operation adds a given directed edge to the graph, then outputs the number of pairs () such that is reachable from and is reachable from .
Can you implement the algorithm from the paper in an ICPC contest?
Input
The first line contains two integers and (, ). Each of the following lines contains two integers and () indicating a newly added directed edge. Parallel edges and self-loops are allowed.
Output
Output integers, one per line: the number of pairs after adding each given edge.