Pagini recente » Cod sursa (job #2169262) | Cod sursa (job #1407550) | Cod sursa (job #1633883) | Cod sursa (job #2407631) | Cod sursa (job #168302)
Cod sursa(job #168302)
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
int main(void){
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,j,i,k;
fin >> n;
int x[n][n];
for (i=0;i<n;i++)
for (j=0;j<n;j++)
fin >> x[i][j];
for (k=0;k<n;k++)
for (i=0;i<n;i++)
for (j=0;j<n;j++)
if (x[i][k] && x[k][j] && x[i][k] + x[k][j] < x[i][j])
x[i][j] = x[i][k] + x[k][j];
for (i=0;i<n;i++){
for (j=0;j<n;j++)
fout << x[i][j] << " ";
fout << "\n";
}
fin.close();
fout.close();
return 0;
}