#P8905. Maximum Group Strength
Maximum Group Strength
Maximum Group Strength
You are given N cows numbered from 1 to N and M pairs of friendships. Each pair indicates a bidirectional friendship among cows. A small group is defined as a set of cows, where each cow can reach every other cow through a sequence of friendships that lie entirely within the group.
The strength of a group is defined as the product of the size of the group and the minimum number of friends (within the group) among all cows in that group. Note that while counting the number of friends for a cow, only friendships connecting to other cows in the same group are counted.
Your task is to find the maximum strength among all small groups.
Formally, if a connected component has k cows and for each cow i the number of friends within the component is di, then its strength is given by \[ S = k \times \min_{1 \le i \le k} d_i. \] Compute the maximum S over all connected components (small groups) in the friendship graph.
inputFormat
The first line contains two integers N and M (2 \(\le\) N \(\le\) 105, 1 \(\le\) M \(\le\) 2 \(\times\) 105), representing the number of cows and the number of friendship pairs.
The following M lines each contain two integers u and v (1 \(\le\) u, v \(\le\) N), indicating that cow u and cow v are friends.
outputFormat
Output a single integer — the maximum strength among all small groups.
sample
4 3
1 2
2 3
2 4
4