luogu#P8905. [USACO22DEC] Strongest Friendship Group G

[USACO22DEC] Strongest Friendship Group G

Problem Description

Farmer John has NN cows (2N1052 \le N \le 10^5), numbered 1N1 \cdots N. Among these cows, there are MM (1M2×1051 \le M \le 2 \times 10^5) pairs of friends.

A group of cows is called a "friend group" if, for every cow in the group, it can reach every other cow in the group by following a sequence of friendships that stays entirely within the group (friendships that connect to cows outside the group are invalid). The "strength" of a friend group is defined as:

(the minimum number of in-group friends among cows in the group) ×\times (the number of cows in the group)

(again, note that friendships connecting to cows outside the group are not counted in this definition).

Find the maximum strength among all friend groups.

Input Format

The first line contains NN and MM.

The next MM lines each contain two integers uiu_i and viv_i, indicating that cows uiu_i and viv_i are friends (1ui,viN1 \le u_i, v_i \le N, uiviu_i \neq v_i). Each unordered pair of cows appears at most once.

Output Format

Output one line containing the maximum strength among all friend groups.

8 10
1 2
1 3
1 4
2 3
2 4
3 4
1 5
2 6
3 7
4 8
12

Hint

Explanation for Sample 1

It can be seen that the maximum strength comes from the group of cows numbered 1,2,3,41, 2, 3, 4. In this group, the minimum number of friends is 33, so the answer is 4×3=124 \times 3 = 12.

Test Point Properties

  • For 1T31 \le T \le 3, test point TT satisfies N16N \le 16.
  • For 4T94 \le T \le 9, test point TT satisfies N1000N \le 1000.
  • For 10T2010 \le T \le 20, test point TT has no additional constraints.

Translated by ChatGPT 5