Pagini recente » Cod sursa (job #506555) | Cod sursa (job #635590) | Cod sursa (job #1024383) | Borderou de evaluare (job #1951567) | Cod sursa (job #875463)
Cod sursa(job #875463)
#include <iomanip>
#include <fstream>
#include <climits>
using namespace std;
const int Max = 101;
int i, j, k, length, value, local_aux, Cost[Max][Max]/*, Path[Max][Max]*/;
void readData(ifstream& in){
in >> length;
for (i = 1; i <= length; i++)
for (j = 1; j <= length; j++)
in >> Cost[i][j];
}
void process(){
for (k = 1; k <= length; k++){
for (i = 1; i <= length; i++){
for (j = 1; j <= length; j++){
if (Cost[i][k] && Cost[k][j] && (Cost[i][j] == 0 || Cost[i][j] > Cost[i][k] + Cost[k][j]) && i != j)
Cost[i][j] = Cost[i][k] + Cost[k][j];
}
}
}
}
void writeData(ofstream& out){
for (i = 1; i <= length; i++){
for (j = 1; j <= length; j++){
out << Cost[i][j] << " ";
}
out << endl;
}
}
int main(int argc, char *argv[]){
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
readData(in);
process();
writeData(out);
return 0;
}