Under construction

Still being built. Things may change

Walks and Queries

Time limit3sMemory limit1024 MB

Summary
After each path is added, count the rooms whose connected component contains an odd cycle, since those rooms can walk every long enough length.
Level

Medium6 of 10

Topics
Union-find, Graph
Solved
No attempts yet

Problem

Seongseo picked NN candidate places near Soongsil University for a room search and numbered them from 11 to NN. Each place has exactly one room. Many factors matter when choosing a room, but Seongseo values freedom to walk above all else.

Path (a,b)(a,b) connects two different places aa and bb. Walking from aa to bb takes 11 unit of time, and walking from bb to aa also takes 11 unit of time. Once you start walking, you cannot turn or stop midway. You must walk for exactly 11 unit of time and arrive at the other end.

Walk starts at some place uu, follows paths, and finally returns to uu. A walk may visit the same place or path many times, but you cannot pause for even a moment.

Seongseo looks around the places and adds paths with a nice atmosphere to a personal path list. A satisfying walk uses only the paths on that list.

Seongseo wants to walk for a long time and return at a chosen moment. Room uu has high walking freedom if, for every integer tt of at least 10610^6, there is a satisfying walk that starts at uu and takes exactly tt units of time.

The path list starts empty. Each time Seongseo finds a good path, the path is added to the list. After each change, find how many rooms have high walking freedom.

Specifically, you must process QQ queries of the following form.

  • a b: Add path (a,b)(a,b) to the path list. Then print the number of rooms with high walking freedom.

For example, suppose there are 66 rooms and the path list is {(1,2),(2,3),(1,3),(4,5)}\{(1,2), (2,3), (1,3), (4,5)\}. The figure above shows this case.

Room 66 has no satisfying walk that takes 10610^6 units of time, so its walking freedom is not high.

Rooms 44 and 55 have satisfying walks that take 10610^6 or 106+210^6+2 units of time, but none that take 106+110^6+1 or 106+310^6+3 units of time. Their walking freedom is not high.

Rooms 11, 22, and 33 have satisfying walks for 10610^6, 106+110^6+1, 106+210^6+2, 106+310^6+3, and so on. Their walking freedom is high.

So in this figure, the number of rooms with high walking freedom is 33.

Input

The first line contains NN and QQ, the number of places and the number of queries, separated by a space.

Each of the next QQ lines contains aia_i and bib_i, the two places connected by the path added in the ii-th query, separated by a space.

Output

For each query, print the answer on its own line.

Constraints

  • 2≤N≤3×1052 \leq N \leq 3 \times 10^5
  • 1≤Q≤6×1051 \leq Q \leq 6 \times 10^5
  • 1≤ai<bi≤N1 \leq a_i < b_i \leq N (1≤i≤Q)(1 \leq i \leq Q)
  • No query is given more than once.
  • All given numbers are integers.

Hint

The input and output are large, so use the fast I/O method described in the language guide on pages 2 to 4 of the problem booklet.

Examples2

  1. Example 1

    Input
    6 5
    1 2
    2 3
    1 3
    4 5
    2 5
    
    Expected output
    0
    0
    3
    3
    5
    
  2. Example 2

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