Pagini recente » Cod sursa (job #2078338) | Cod sursa (job #2654743) | Cod sursa (job #182833) | Cod sursa (job #2780943) | Cod sursa (job #3255396)
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int NMAX = 105;
const int INF = 1e9;
int a[NMAX][NMAX];
int main()
{
int n;
fin >> n;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
fin >> a[i][j];
if(a[i][j] == 0){
a[i][j] = INF;
}
}
}
for(int k = 1; k <= n; ++k){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(i != j){
a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
}
}
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(a[i][j] == INF){
fout << 0 << " ";
}
else{
fout << a[i][j] << " ";
}
}
fout << "\n";
}
return 0;
}