Pagini recente » Cod sursa (job #3255714) | Cod sursa (job #1151854) | Cod sursa (job #1272684) | Cod sursa (job #2193945) | Cod sursa (job #2004268)
#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][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;
}