Pagini recente » Cod sursa (job #2692832) | Cod sursa (job #1981725) | Monitorul de evaluare | Cod sursa (job #1869979) | Cod sursa (job #1992018)
#include <fstream>
#define Vmax 100
using namespace std;
int main()
{
ifstream input("royfloyd.in");
ofstream output("royfloyd.out");
int V;
input >> V;
int i, j, k;
int dist[Vmax][Vmax];
for(i = 0; i < V; i ++)
for(j = 0; j < V; j ++)
dist[i][j] = 1 << 16;
output << dist[2][2] << '\n';
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][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;
}