Friends
Time Limit: 0.5 sec
The Problem
In Outsbook Programming School there are N students. The Outsbook Authority announce that they will give an award to the largest friend group. Outsbook have a database of all friend relation as a pair (A, B). Can you help the Outsbook authority to find the largest group member?
How can you make a friend group, the friends of your friend are also your friends (i.e. if A and B are friends and B and C are friends then A and C are friends, too).
Your task is to count how many student there are in the largest group of friends.
The Input
Input consists of several test cases. The first line of each test case contains the numbers N and M, where N is the number of students in Outsbook Programming School (1 ≤ N ≤ 30000) and M is the number of pairs of students (0 ≤ M ≤ 500000), which are known to be friends. Each of the following M lines consists of two integers A and B (1 ≤ A ≤ N, 1 ≤ B ≤ N, A != B) which describe that A and B are friends. There could be repetitions among the given pairs. Input is terminated when N=0 and M=0.
The Output
The output for each test case should contain one number denoting how many students there are in the largest group of friends in a separate line.
Sample Input
3 2
1 2
2 3
10 12
1 2
3 1
3 4
5 4
3 5
4 6
5 2
2 1
7 1
1 2
9 10
8 9
0 0
Sample Output
3
7
Explanation
Case 1: There only one friend group {1, 2, and 3}, total member in this group is 3, so 3 is the answer.
Case 2: There are 2 friend groups {1, 2, 3, 4, 5, 6, and 7} and {8, 9, and 10}. In group 1 have 7 students and in group 2 have 3 students. So, 7 is the answer.
Online Practice Contest 4 [School & College Level]
Problem Setter: Shahin ShamS