Pagini recente » Cod sursa (job #2910244) | Cod sursa (job #1029643) | Cod sursa (job #713356) | Cod sursa (job #164803) | Cod sursa (job #2004269)
#include <fstream>
using namespace std;
const int MaxN = 101;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int mat[MaxN][MaxN];
int main()
{
int n;
f >> n;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
f >> mat[i][j];
}
}
for(int k = 0; k < n; ++k){
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(mat[i][k] && mat[k][j] && (mat[i][k] + mat[k][j] < mat[i][j] || !mat[i][j]) && i != j){
mat[i][j] = mat[i][k] + mat[k][j];
}
}
}
}
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
g << mat[i][j] << ' ';
}
g << '\n';
}
return 0;
}