You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
784 B

#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;
}