#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, w[N][N];
int a[N/2], b[N/2];
bool chosen[N];
int ans;
void dfs(int x) {
if (x > n/2) {
int w1 = 0, w2 = 0;
for (int i = 1; i <= n/2; i ++) {
for (int j = i + 1; j <= n/2; j ++) {
w1 = max(w1, w[a[i]][a[j]]);
}
}
for (int i = 1; i <= n/2; i ++) {
for (int j = i + 1; j <= n/2; j ++) {
w2 = max(w2, w[b[i]][b[j]]);
}
}
if (w1 > w2) ans = max(ans, w1);
return;
}
for (int i = 1; i <= n; i ++) {
if (!chosen[i]) {
a[x] = i;
chosen[i] = true;
int t = 0;
for (int j = 1; j <= x; j ++) {
for (int k = 1; k <= n; k ++) {
if (!chosen[k] && w[a[j]][k] > w[a[j]][t]) {
t = k;
}
}
}
b[x] = t;
chosen[t] = true;
dfs(x + 1);
chosen[i] = false;
chosen[t] = false;
}
}
}
int main() {
cin >> n;
for (int i = 1; i < n; i ++) {
for (int j = 1; j <= n - i; j ++) {
int t;
cin >> t;
w[i][i+j] = w[i+j][i] = t;
}
}
dfs(1);
if (ans == 0) cout << 0 << endl;
else cout << 1 << endl << ans << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct info {
int x, y, w;
}a[260000];
bool cmp (info s, info t) { return s.w > t.w; }
int main() {
cin >> n;
for (int i = 1; i < n; i ++) {
for (int j = 1; j <= n - i; j ++) {
int t;
cin >> t;
a[++ m] = (info) {i, i + j, t};
}
}
sort(a + 1, a + 1 + m, cmp);
set <int> s;
for (int i = 1; i <= m; i ++) {
int x = a[i].x, y = a[i].y, w = a[i].w;
if (s.count(x) || s.count(y)) {
cout << 1 << endl << w;
return 0;
}
else {
s.insert(x);
s.insert(y);
}
}
cout << 0;
return 0;
}
|