PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000066. Những cây cầu xuống cấp (Decayed Bridges)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những cây cầu xuống cấp (Decayed Bridges)

Decayed Bridges

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN islands connected by MM undirected bridges. Initially, every island can be reached from every other island. Bridges 1,2,…,M1,2,\ldots,M collapse in this order and cannot be used afterwards.

After each collapse, the inconvenience is the number of pairs (u,v)(u,v), u<vu<v, such that no path between uu and vv remains. Find the inconvenience after every collapse.

The bridges are numbered by their order in the input. When one bridge collapses, only that bridge disappears; all other bridges remain usable. A pair of islands is counted as disconnected only when no path between them remains, even if the previous path went through several intermediate islands.

Initially all islands are mutually reachable. After every bridge has collapsed, none of them are connected to another. Each requested answer refers to the graph immediately after the corresponding collapse, not just before it.

Input

The first line contains N,MN,M. Each of the next MM lines contains Ai,BiA_i,B_i, the endpoints of bridge ii.

Output

Print MM lines. Line ii contains the number of disconnected unordered island pairs after the first ii bridges collapse.

Subtasks

  • Subtask 1 (20 points): 2≤N≤302\le N\le 30; 1≤M≤1201\le M\le 120; 1≤Ai<Bi≤N1\le A_i<B_i\le N; every pair of endpoints is distinct; the initial graph is connected.
  • Subtask 2 (30 points): 2≤N≤30002\le N\le 3000; 1≤M≤60001\le M\le 6000; 1≤Ai<Bi≤N1\le A_i<B_i\le N; every pair of endpoints is distinct; the initial graph is connected.
  • Subtask 3 (50 points): 2≤N≤1000002\le N\le 100000; 1≤M≤1000001\le M\le 100000; 1≤Ai<Bi≤N1\le A_i<B_i\le N; every pair of endpoints is distinct; the initial graph is connected.

Examples

Input

4 5
1 2
3 4
1 3
2 3
1 4

Output

0
0
4
5
6

Explanation

The first two bridge collapses leave the graph connected, so both answers are 00. After edge (1,3)(1,3) collapses, the remaining components are {1,4}\{1,4\} and {2,3}\{2,3\}, yielding 2⋅2=42\cdot2=4 disconnected pairs. The next collapse gives 55 disconnected pairs. After the last bridge collapses, all inom{4}{2}=6 pairs are disconnected.