Under construction

Still being built. Things may change

Link Cut Digraph

Time limit3sMemory limit512 MB

Summary
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 nn vertices and no edges at first. There are mm operations. Each operation adds a given directed edge to the graph, then outputs the number of pairs (u,v)(u, v) (1≤u<v≤n1 \leq u < v \leq n) such that uu is reachable from vv and vv is reachable from uu.

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

Input

The first line contains two integers nn and mm (1≤n≤1051 \leq n \leq 10^5, 1≤m≤2.5⋅1051 \leq m \leq 2.5 \cdot 10^5). Each of the following mm lines contains two integers uu and vv (1≤u,v≤n1 \leq u, v \leq n) indicating a newly added directed edge. Parallel edges and self-loops are allowed.

Output

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

Examples1

  1. Example 1

    Input
    4 6
    1 2
    2 3
    2 1
    3 4
    4 3
    3 2
    
    Expected output
    0
    0
    1
    1
    2
    6