Pagini recente » Cod sursa (job #1827728) | Cod sursa (job #2609985) | Cod sursa (job #990741) | Cod sursa (job #990317) | Cod sursa (job #1992027)
#include <fstream>
#define Vmax 110
#define maxim 1005
using namespace std;
int dist[Vmax][Vmax];
int main()
{
ifstream input("royfloyd.in");
ofstream output("royfloyd.out");
int V;
input >> V;
int i, j, k;
int x;
for(i = 0; i < V; i ++)
for(j = 0; j < V; j ++)
{
input >> x;
if(i != j && ! x)
dist[i][j] = maxim;
else dist[i][j] = x;
}
for(k = 0; k < V; k ++)
for(i = 0; i < V; i ++)
for(j = 0; j < V; j ++)
if(dist[i][j] > dist[i][k] + dist[k][j])
dist[i][j] = dist[i][k] + dist[k][j];
for(i = 0; i < V; i ++)
{
for(j = 0; j < V; j ++)
output << dist[i][j] << ' ';
output << '\n';
}
return 0;
}