A company tracks n employees, numbered 1 to n. There are m referral links; each link connects two employees who know each other directly. Two employees belong to the same "referral circle" if one can be reached from the other through a chain of links (a link is undirected: knowing works both ways). An employee with no links is a circle of size one.
Report the size (number of employees) of the largest referral circle.
Line 1: two integers n and m — number of employees (1-indexed) and number of links.
Next m lines: two integers u v — an undirected link between employee u and employee v. Links may repeat.
A single integer: the number of employees in the largest referral circle.
Example 1
Input
5 3 1 2 2 3 4 5
Expected
3
Explanation
{1,2,3} has size 3, {4,5} has size 2. The largest circle has 3 employees.
Example 2
Input
3 0
Expected
1
Explanation
No links at all, so every employee is their own circle of size 1.
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 →