Under construction

Still being built. Things may change

Making Friends on Joitter is Fun

Time limit2sMemory limit512 MB

Summary
After each day's follow event, find the maximum total number of follows once the exchange event has been applied until no valid (x, y, z) triple remains.
Level

Medium7 of 10

Topics
Graph, Union-find, Implementation
Solved
No attempts yet

Problem

Joitter is a trending social media service where you can share your memories with your friends.

In Joitter, you can follow other users. For example, when user a follows user b, user a can read user b's posts on the timeline. In this case, user b may or may not follow user a back. However, a user cannot follow themselves, and a user cannot follow the same user b more than once.

N users, user 1, user 2, ..., user N, have started using Joitter. At first, none of them follows any other user. From now on, for M days, following events occur: on the i-th day, user A_i follows user B_i.

The Joitter staff plans to hold a social exchange event on the service once during the M days. A social exchange event works as follows:

  1. Select one user. Call this user x.
  2. Select one user that x currently follows. Call this user y.
  3. Select one user z such that z is different from x, x does not follow z, y follows z, and z follows y.
  4. x follows z.
  5. Repeat these steps until no tuple (x, y, z) can be selected.

The staff has not decided when to hold the event. For each i (1≤i≤M1 \le i \le M), they want to know the maximum possible total number of users that each user follows after the social exchange event, assuming the event happens right after the following event of day i. The social exchange event finishes before the following event of the next day.

Write a program that calculates this maximum for each i.

Input

Read the following data from the standard input. All values are integers.

N M
A1 B1
.
.
.
AM BM

Output

Write M lines to the standard output. On the i-th line, output the maximum total number of users each user follows after the social exchange event, if the event happens right after the following event of day i.

Constraints

  • 2≤N≤1000002 \le N \le 100000
  • 1≤M≤3000001 \le M \le 300000
  • 1≤Ai≤N1 \le A_i \le N (1≤i≤M1 \le i \le M)
  • 1≤Bi≤N1 \le B_i \le N (1≤i≤M1 \le i \le M)
  • (Ai,Bi)≠(Aj,Bj)(A_i, B_i) \ne (A_j, B_j) (1≤i<j≤M1 \le i < j \le M)
  • Time limit: 2000 ms. Memory limit: 512 MB.

Examples2

  1. Example 1

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

    Input
    6 10
    1 2
    2 3
    3 4
    4 5
    5 6
    6 5
    5 4
    4 3
    3 2
    2 1
    
    Expected output
    1
    2
    3
    4
    5
    7
    11
    17
    25
    30