#P7212. [JOISC 2020] ジョイッターで友だちをつくろう

[JOISC 2020] ジョイッターで友だちをつくろう

Description

On Joitter, you can follow other users, but you cannot follow yourself and you cannot follow the same user twice. That is, following the same user multiple times only counts once.

There are NN new users and MM days.

On day ii, user AiA_i follows user BiB_i.

Also, after the follow action, a social event is held with the following rules:

  1. Choose a user xx.
  2. Choose a user yy that is followed by user xx.
  3. Choose a user zz such that zxz\not=x, xx does not follow zz, and yy and zz follow each other.
  4. Make xx follow zz.
  5. Repeat 1,2,3,41,2,3,4 until no suitable triple (x,y,z)(x,y,z) can be chosen.

You need to compute, for each ii, the total number of follows after day ii.

Input Format

The first line contains two integers N,MN,M.

The next MM lines each contain two integers Ai,BiA_i,B_i.

Output Format

Output MM lines in total. Each line contains one number. Line ii represents the total number of follows after day ii.

4 6
1 2
2 3
3 2
1 3
3 4
4 3
1
2
4
4
5
9
6 10
1 2
2 3
3 4
4 5
5 6
6 5
5 4
4 3
3 2
2 1
1
2
3
4
5
7
11
17
25
30

Hint

Subtasks

For 100%100\% of the testdata, it is guaranteed that 2N1052\le N\le 10^5, 1M3×1051\le M\le 3\times 10^5, 1Ai,BiN1\le A_i,B_i\le N, AiBiA_i\not=B_i, and (Ai,Bi)(Aj,Bj)(A_i,B_i)\not=(A_j,B_j).

Subtask ID NN\le Score
11 5050 11
22 2×1032\times 10^3 1616
33 None 8383

Notes

This problem is translated from Day 2 T2 “ジョイッターで友だちをつくろう” of The 19th Japanese Olympiad in Informatics Spring Training Camp, T2 ジョイッターで友だちをつくろう.

Translated by ChatGPT 5