Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
51584 | AK2022071356 | 最优子图 | C++ | 解答错误 | 10 | 14 MS | 4324 KB | 1099 | 2022-07-13 11:54:04 |
#include <bits/stdc++.h> using namespace std; const int N(510); struct Node{ int v,w;bool vis; }; int n,k; int e[N][N]; vector<Node> g[N << 1]; long long ans,sum1[N],sum2[N]; inline int read(){ register int x(0); register short w(1); register char c(getchar()); for (;c < '0' || c > '9';c = getchar()) if (c == '-') w = -1; for (;c >= '0' && c <= '9';c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * w; } void Init(){ n = read(),k = read(); for (int i(1);i <= n;i++) for (int j(1);j <= n;j++){ int x(read()); if (i > j) g[i].push_back(Node{j,x}),g[j].push_back(Node{i,x}),e[i][j] = x; } return ; } void Solve(){ for (int i(1);i <= n;i++) for (int j(0);j < g[i].size();j++) sum1[i] += g[i][j].w,sum2[i] += (k - g[i][j].w); long long maxn(-1e9);int ind(0); for (int i(1);i <= n;i++) if (maxn < sum2[i]) maxn = sum2[i],ind = i; for (int i(1);i <= n;i++) for (int j(1);j <= n;j++) ans += e[i][j]; ans -= sum1[ind]; cout << ans + maxn; return ; } int main(){ Init();Solve(); return 0; }