Pagini recente » Cod sursa (job #225045) | Cod sursa (job #1467949) | Cod sursa (job #2736253) | Cod sursa (job #1483459) | Cod sursa (job #1740317)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n;
int 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];
}
}
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if((mat[i][j] > mat[i][k] + mat[k][j] or !mat[i][j]) and mat[i][k] and mat[k][j] and i != j){
mat[i][j] = mat[i][k] + mat[k][j];
}
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
out << mat[i][j] << ' ';
}
out << '\n';
}
return 0;
}