Pagini recente » Cod sursa (job #1703225) | Cod sursa (job #2702514) | Cod sursa (job #2541346) | Cod sursa (job #502657) | Cod sursa (job #1992026)
#include <fstream>
#define Vmax 110
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;
for(i = 0; i < V; i ++)
for(j = 0; j < V; j ++)
input >> dist[i][j];
for(k = 0; k < V; k ++)
for(i = 0; i < V; i ++)
for(j = 0; j < V; j ++)
if(dist[i][k] != 0 && dist[k][j] != 0 && i != j && (dist[i][j] > dist[i][k] + dist[k][j] || ! dist[i][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;
}