Pagini recente » Cod sursa (job #3152191) | Cod sursa (job #3202570) | Cod sursa (job #384686) | Cod sursa (job #3247752) | Cod sursa (job #1926876)
#include <bits/stdc++.h>
#define N 105
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
int totalNodes;
int nodes[N][N];
inline void readVaraibles(void){
fin >> totalNodes;
for ( int indexY = 1; indexY <= totalNodes; indexY++ )
for ( int indexX = 1; indexX <= totalNodes; indexX++ )
fin >> nodes[indexY][indexX];
}
inline void royFloyd(void){
for ( int indexK = 1; indexK <= totalNodes; indexK++ )
for ( int indexY = 1; indexY <= totalNodes; indexY++ )
for ( int indexX = 1; indexX <= totalNodes; indexX++ )
if ( nodes[indexY][indexK] and nodes[indexK][indexX] )
if ( nodes[indexY][indexX] > nodes[indexY][indexK] + nodes[indexK][indexX] or !nodes[indexY][indexX])
if ( indexX != indexY )
nodes[indexY][indexX] = nodes[indexY][indexK] + nodes[indexK][indexX];
}
inline void printSolution(void){
for ( int indexY = 1; indexY <= totalNodes; indexY++ ){
for ( int indexX = 1; indexX <= totalNodes; indexX++ )
fout << nodes[indexY][indexX] << " ";
fout << "\n";
}
}
int main(){
readVaraibles();
royFloyd();
printSolution();
}