parent
40e4ca2839
commit
311747d542
@ -0,0 +1,29 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 210;
|
||||
int n, g[N][N];
|
||||
const int INF = 0x3f3f3f3f;
|
||||
int ans = INF;
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++) {
|
||||
cin >> g[i][j];
|
||||
if (g[i][j] == 0 && i != j) g[i][j] = INF; // 建图(注意i==j要为0)
|
||||
}
|
||||
// floyd
|
||||
for (int k = 1; k <= n; k++)
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++)
|
||||
if (g[i][j] > g[i][k] + g[k][j])
|
||||
g[i][j] = g[i][k] + g[k][j];
|
||||
|
||||
int s;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
s = 0;
|
||||
for (int j = 1; j <= n; j++) s += g[i][j];
|
||||
if (s < ans) ans = s;
|
||||
}
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue