Link Cut Digraph

간선이 없는 정점 n개짜리 방향 그래프에 간선을 하나씩 추가하면서, 매번 서로 도달 가능한 정점 쌍의 개수를 구한다.

어려움9그래프유니온 파인드분할 정복DFS아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

After reading the paper Incremental Topological Ordering and Strong Component Maintenance, you came up with the following problem.

You are given a graph with nn vertices. There are no edges initially. There are mm operations. Each operation is first to add a given directed edge to the graph, and then to output the number of pairs (u,v)(u, v) (1u<vn1 \leq u < v \leq n) such that uu is reachable from vv and vv is reachable from uu.

Can you implement the algorithm described in the paper in an ICPC contest?

입력

The first line contains two integers nn and mm (1n1051 \leq n \leq 10^5, 1m2.51051 \leq m \leq 2.5 \cdot 10^5).

Each of the following mm lines contains two integers uu and vv (1u,vn1 \leq u, v \leq n) indicating a newly added directed edge. Parallel edges and self-loops are allowed.

출력

Output mm integers, one per line: the requested number of pairs after adding each given edge.