Pagini recente » Cod sursa (job #1226237) | Cod sursa (job #3208587) | Cod sursa (job #2375611) | Cod sursa (job #2819626) | Cod sursa (job #1194961)
#include <fstream>
using namespace std;
int a[102][102], n, i, j, k;
int main() {
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
fin>>n;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
fin>>a[i][j];
for (k=1;k<=n;k++)
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (i!=j && a[i][k] != 0 && a[k][j]!=0 && (a[i][j] > a[i][k] + a[k][j] || a[i][j] == 0))
a[i][j] = a[i][k] + a[k][j];
for (i=1;i<=n;i++) {
for (j=1;j<=n;j++)
fout<<a[i][j]<<" ";
fout<<"\n";
}
return 0;
}