Pagini recente » Monitorul de evaluare | Borderou de evaluare (job #1598851) | Diferente pentru utilizator/rexlcd intre reviziile 4 si 5 | Cod sursa (job #1522098) | Cod sursa (job #2639678)
#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 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])<<" ";
}