Pagini recente » Cod sursa (job #1075794) | Cod sursa (job #450561) | Cod sursa (job #2198679) | Cod sursa (job #1220341) | Cod sursa (job #2639679)
#include <bits/stdc++.h>
#define oo 1500
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 k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i != j && 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])<<" ";
}