Pagini recente » Cod sursa (job #328080) | Cod sursa (job #1442820) | Cod sursa (job #2455612) | Cod sursa (job #1494933) | Cod sursa (job #2343644)
#include <fstream>
#define NMAX 101
#define INF 1001
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int cost[NMAX][NMAX];
void read();
int main(){int i, j, k;
read();
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
for(k = 1; k <= n; k++)
if(i != k && j != k && cost[i][j] < INF)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
if(cost[i][j] < INF) fout << cost[i][j] << ' ';
else fout << "0 ";
}
fout << '\n';
}
return 0;
}
void read(){int i, j;
fin >> n;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++){
fin >> cost[i][j];
if(!cost[i][j]) cost[i][j] = INF;
}
}