Pagini recente » Cod sursa (job #311080) | Cod sursa (job #1068262) | Cod sursa (job #3183107) | Cod sursa (job #1816828) | Cod sursa (job #1771967)
#include <bits/stdc++.h>
using namespace std;
#define Nmax 111
#define inf 0x3f3f3
class DirectedGraph {
private :
int nodes;
int dist[Nmax][Nmax];
public :
DirectedGraph(int n){
this->nodes = n;
memset(dist,inf,sizeof dist);
}
void setCost (int from,int to,int cost){
dist[from][to] = cost;
}
void royFloyd(){
int n = this->nodes;
for (int i=0;i<n;++i)
for (int j=0;j<n;++j)
for (int k=0;k<n;++k)
dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
}
int getDist(int i,int j){
return dist[i][j];
}
};
int main(void){
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n,aux;
cin>>n;
DirectedGraph *graph = new DirectedGraph(n);
for (int i=0;i<n;++i){
for (int j=0;j<n;++j){
cin>>aux;
graph->setCost(i,j,aux);
}
}
graph->royFloyd();
for (int i=0;i<n;++i){
for (int j=0;j<n;++j){
cout<<graph->getDist(i,j)<<" ";
}
cout<<"\n";
}
return 0;
}