Red Huang

Red Huang

Problem 10608 Friends, Maximum Friends Group

There are N people in the town, following a proverb: "The friends of my friends are also my friends." A and B are friends, B and C are friends, so C and A are also friends.

Read in two integers N and M, where N represents citizens 1 - N in the town, and then there will be M lines of data. Each line contains two integers a, b, indicating that citizen a and citizen b are friends. Finally, please calculate the number of the largest friends group in this town.

In fact, just define a friend group number for each group. If both parties do not have a group number, define a new group number for both individuals, and increase the count to 2; if one of the individuals does not have a group number, add them to the group with a number. If both individuals have group numbers, change the group number of one party's friends to the other party's group number, and add the count of the other party's group number to the count.

Declare arrays and initialize friend group numbers and group counts at the beginning:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.