Pagini recente » Cod sursa (job #832640) | Cod sursa (job #621060) | Cod sursa (job #950712) | Cod sursa (job #1311116) | Cod sursa (job #2645675)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 105;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int dist[N][N];
int main()
{
fin >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
fin >> dist[i][j];
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
if(i != k)
for(int j = 1; j <= n; j++)
if(i != j && dist[i][k] != 0 && dist[k][j] != 0)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
fout << dist[i][j] << ' ';
fout << '\n';
}
return 0;
}