Pagini recente » Cod sursa (job #2375042) | Cod sursa (job #2910819) | Cod sursa (job #2269254) | Cod sursa (job #2961307) | Cod sursa (job #1740313)
#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] and mat[i][k] and mat[k][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;
}