Pagini recente » Cod sursa (job #2546074) | Cod sursa (job #3255404) | Cod sursa (job #1118219) | Cod sursa (job #745165) | Cod sursa (job #2823653)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int INF = 1e9;
int n, mat[101][101];
int main() {
fin >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) {
fin >> mat[i][j];
if(!mat[i][j] && i != j)
mat[i][j] = INF;
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
fout << mat[i][j] << " ";
fout << "\n";
}
return 0;
}