Loading...
Loading...
Loading...
A class has n students numbered 1 to n. Each of m pairs "a b" are friends. A friend group is a set of students where any two are linked through a chain of friends. Print the number of students in the largest friend group.
Example
Input
7 4 1 2 2 3 4 5 6 6
Output
3
The group {1, 2, 3} is the largest.
Try the problem first. Open one hint at a time.
Union-Find with a size list gives the group size at the leader.
Update the best size after every union.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor