// MST
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct Edge {
int from;
int to;
int weight;
} e[125050];
int p[505];
bool cmp(Edge a, Edge b) {
return a.weight < b.weight;
}
// 根节点:本身或父节点的根节点
int find(int x) {
return (x == p[x]) ? x : find(p[x]);
}
int main(int argc, char **argv) {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int w, k = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
cin >> w;
if (i < j) {
e[k].from = i;
e[k].to = j;
e[k].weight = w;
k++;
}
}
// kruskal
sort(e, e + k, cmp);
// 并查集初始化
for (int i = 0; i < n; ++i)
p[i] = i;
int max = 0;
for (int i = 0; i < k; ++i) {
int x = find(e[i].from);
int y = find(e[i].to);
if (x != y) {
if (max < e[i].weight)
max = e[i].weight;
p[x] = y; // 并入连通分量
}
}
// 题目输出格式
if (t)
cout << max << endl << endl;
else
cout << max << endl;
}
return 0;
}
09-11
09-11
09-11
09-11
09-11