#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.
Mục lục đề ⌄
Liên kết nhóm (Group Connections)
Group Connections
Version: Phuoc Hung OJ Extended
Problem Statement

A club has members, numbered through . Initially each member forms a separate group; thus there are groups, each of size one.
The club records connections in order. At step , members and 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 and .
Each of the next lines contains integers and , representing connection .
Output
Print exactly lines. Line contains two space-separated integers: the number of groups and the largest group size after processing connection .
Subtasks
- Subtask 1 (30 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (40 points): ; ; for every .
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 joins and : groups, maximum size . Step joins and : groups, maximum size . Step joins groups and into a size- group: groups remain. Steps and connect members already in the same group (including the self-loop –), 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 – and –; the result stays at groups of maximum size . The last step merges members and , leaving groups and a largest group of size .
Example 3
Input
4 3
1 2
2 3
3 4
Output
3 2
2 3
1 4
Explanation
After step , group has size and groups remain. After step , group has size , with groups left. After step , all four members are in one group, producing 1 4.
Liên quan
Trong các cuộc thi sau: