Grouping Game (APCS 2025-06 Expert)
2.0s 256MPartition \(n\) people into exactly \(k\) nonempty groups. Pairwise distances are given. The quality is the smallest distance between people in different groups. Maximize this quality.
Input Format
Read \(n,k\) and an \(n\) by \(n\) distance matrix.
Output Format
Print the maximum quality.
Constraints
\(2\le k\le n\le500\). Distances are symmetric with zero diagonal and other entries in \([1,10^8]\).
Scoring
- 20 points: \(n\le10\) and \(k=2\).
- 80 points: No additional restrictions.
Each scored test is worth 5 points.
Sample Input 1
3 2
0 2 1
2 0 3
1 3 0
Sample Output 1
2
Sample Input 2
5 3
0 5 6 1 3
5 0 3 4 2
6 3 0 4 7
1 4 4 0 5
3 2 7 5 0
Sample Output 2
3
Source
APCS 2025-06 public archive version: q839。
Log in to write and submit code.
Log in