#DSU0000041. Phân nhóm bạn bè (Friends)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân nhóm bạn bè (Friends)
Friends
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are people numbered from to , and you are given pairs of acquaintances. Friendship is considered undirected and transitive: if is a friend of , and is a friend of , then and are also regarded as friends. Thus, people linked by any chain of acquaintances belong to the same friendship circle.
Partition all people into groups, with each person assigned to exactly one group. No two distinct people in the same group may be friends under this definition. There are no restrictions between different groups.
Find the minimum number of groups in a valid partition.
Input
The first line contains . Each of the next lines contains .
Output
Print the minimum number of groups.
Subtasks
- Subtask 1 (20 points): , ; , ; pairs may repeat.
- Subtask 2 (30 points): , ; , ; pairs may repeat.
- Subtask 3 (50 points): , ; , ; pairs may repeat.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Explanation
Friendship components are {1,2,5} and {3,4}. The three people in the largest component require three distinct groups; {1,3}, {2,4}, {5} is a valid partition.