#DSU0000078. Nhóm bạn bè mạnh nhất (Strongest Friendship Group)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nhóm bạn bè mạnh nhất (Strongest Friendship Group)
Strongest Friendship Group
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
There are cows and undirected friendship pairs. A non-empty group is valid if its members are connected using only friendship edges within that group.
Its strength equals the number of group members multiplied by the minimum number of friends that any member has within the group. Friendships to cows outside the group do not count. Find the maximum strength over all valid groups.
Friendships are undirected, and no unordered pair appears more than once. A group need not contain every cow, but every two members must be connected by a chain of friendships entirely inside the group.
The degree of a cow within the group counts only friends that are also group members. The cow's total number of friends on the farm is irrelevant to the group's strength. A group consisting of a single cow has strength .
Input
The first line contains . Each of the next lines contains one friendship pair .
Output
Print one integer: the largest strength of a valid friendship group.
Subtasks
- Subtask 1 (20 points): ; ; , ; each friendship is specified at most once.
- Subtask 2 (30 points): ; ; , ; each friendship is specified at most once.
- Subtask 3 (50 points): ; ; , ; each friendship is specified at most once.
Examples
Input
8 10
1 2
1 3
1 4
2 3
2 4
3 4
1 5
2 6
3 7
4 8
Output
12
Explanation
Cows form a connected group in which every member has exactly three friends inside the group. Its strength is . Adding the other cows cannot yield a stronger friendship group, so the optimum is .