Pagini recente » Cod sursa (job #2166552) | Cod sursa (job #2603893) | Cod sursa (job #728752) | Cod sursa (job #2075795) | Cod sursa (job #2639677)
#include <bits/stdc++.h>
#define oo (1 << 29)
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n, mat[105][105];
int main(){
in>>n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++){
in>>mat[i][j];
if(!mat[i][j])
mat[i][j] = oo;
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i != j)
for(int k = 1; k <= n; k++)
if(mat[i][j] > mat[i][k] + mat[k][j])
mat[i][j] = mat[i][k] + mat[k][j];
for(int i = 1; i <= n; i++, out<<"\n")
for(int j = 1; j <= n; j++)
out<<(mat[i][j] == oo ? 0 : mat[i][j])<<" ";
}