Pagini recente » Cod sursa (job #81442) | Cod sursa (job #1854390) | Cod sursa (job #2837891) | Cod sursa (job #2715083) | Cod sursa (job #2075814)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n, w[105][105];
void citire(){
in >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
in >> w[i][j];
}
void roy_floyd(){
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(w[i][k] != 0 && w[k][j] != 0 && i != j && (w[i][k] + w[k][j] < w[i][j] || w[i][j] == 0))
w[i][j] = w[i][k] + w[k][j];
}
void afisare(){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
out << w[i][j] << " ";
out << '\n';
}
}
int main()
{
in.sync_with_stdio();
out.sync_with_stdio();
citire();
roy_floyd();
afisare();
return 0;
}