Problem 99C. Aggressive Cows: General Pasture ≡

Author:Pavel Mesenev   Time limit:3 sec
Input file:Standard input   Memory limit:512 Mb
Output file:Standard output  

Statement

The same farmer as before, the same aggressive cows — but this time the n pastures are not stalls on a tidy line. They are connected by a tangle of fences, ditches and informal cow gossip, so all the farmer can tell you is a number di,j for every pair of pastures: "how far apart I'd call i and j". These numbers need not come from any map or line, and need not satisfy the triangle inequality.

Place C cows into C distinct pastures so that the minimum distance between any two cows is as large as possible.

Output that largest possible minimum distance.

Input format

The first line contains two integers n and C. Each of the next n lines contains n integers — row i of the distance matrix di,0… di,n − 1. The matrix is symmetric (di,j = dj,i); the diagonal entries di,i are present but irrelevant and may be ignored.

Output format

Print one integer — the maximum achievable minimum distance between two cows.

Constraints

2 ≤ C ≤ n ≤ 3000

0 ≤ di,j ≤ 109 for i ≠ j, di,j = dj,i

the matrix need not satisfy the triangle inequality

Sample tests

No. Standard input Standard output
1
4 2
0 5 1 1
5 0 1 1
1 1 0 5
1 1 5 0
5
2
5 3
0 2 2 1 1
2 0 2 1 1
2 2 0 1 1
1 1 1 0 2
1 1 1 2 0
2
3
2 2
0 7
7 0
7

0.041s 0.012s 16