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

#CT0000148. Liên kết nhóm (Group Connections)

Bài tập này chưa được xếp vào lộ trình.

Liên kết nhóm (Group Connections)

Group Connections

Version: Phuoc Hung OJ Extended

Problem Statement

A club has nn members, numbered 11 through nn. Initially each member forms a separate group; thus there are nn groups, each of size one.

The club records mm connections in order. At step ii, members uiu_i and viv_i become connected. Two members belong to the same group if a chain of recorded connections links them. A connection between two different groups merges both entire groups.

Connections may be repeated, and a member may be connected to themselves. Such a step does not change the groups when both endpoints already belong to the same group.

After every connection, report the number of groups and the size of the largest group.

Input

The first line contains two positive integers nn and mm.

Each of the next mm lines contains integers uiu_i and viv_i, representing connection ii.

Output

Print exactly mm lines. Line ii contains two space-separated integers: the number of groups and the largest group size after processing connection ii.

Subtasks

  • Subtask 1 (30 points): 1≤n≤501\le n\le 50; 1≤m≤1001\le m\le 100; 1≤ui,vi≤n1\le u_i,v_i\le n for every 1≤i≤m1\le i\le m.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤m≤50001\le m\le 5000; 1≤ui,vi≤n1\le u_i,v_i\le n for every 1≤i≤m1\le i\le m.
  • Subtask 3 (40 points): 1≤n≤2⋅1051\le n\le 2\cdot 10^5; 1≤m≤2⋅1051\le m\le 2\cdot 10^5; 1≤ui,vi≤n1\le u_i,v_i\le n for every 1≤i≤m1\le i\le m.

Examples

Example 1

Input

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

Output

4 2
3 2
2 4
2 4
2 4

Explanation

Initially there are five singleton groups. Step 11 joins 11 and 22: 44 groups, maximum size 22. Step 22 joins 33 and 44: 33 groups, maximum size 22. Step 33 joins groups {1,2}\{1,2\} and {3,4}\{3,4\} into a size-44 group: 22 groups remain. Steps 44 and 55 connect members already in the same group (including the self-loop 55–55), so both outputs remain 2 4.

Example 2

Input

6 3
1 1
2 2
1 2

Output

6 1
6 1
5 2

Explanation

The first two steps are self-connections 11–11 and 22–22; the result stays at 66 groups of maximum size 11. The last step merges members 11 and 22, leaving 55 groups and a largest group of size 22.

Example 3

Input

4 3
1 2
2 3
3 4

Output

3 2
2 3
1 4

Explanation

After step 11, group {1,2}\{1,2\} has size 22 and 33 groups remain. After step 22, group {1,2,3}\{1,2,3\} has size 33, with 22 groups left. After step 33, all four members are in one group, producing 1 4.