A residence hall has n students, numbered 1 through n. There are m recorded friendships; each friendship links two students, and friendship is mutual. Students a and b belong to the same friendship circle if a can reach b through a chain of friendships.
Report the size (number of students) of the largest friendship circle.
n and m.m lines: two integers u and v (1-indexed), a friendship between student u and student v. The same pair may be listed more than once.A single integer: the number of students in the largest friendship circle.
Example 1
Input
5 3 1 2 2 3 4 5
Expected
3
Explanation
One circle {1,2,3} has 3 students and the other {4,5} has 2, so the largest circle has 3 students.
Example 2
Input
4 0
Expected
1
Explanation
With no friendships every student is alone, so the largest circle has just 1 student.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →