Pagini recente » Cod sursa (job #721174) | Cod sursa (job #1373197) | Cod sursa (job #1391471) | Cod sursa (job #1696867) | Cod sursa (job #2665780)
#include <bits/stdc++.h>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int n;
int mat[105][105];
int oo=2000000009;
int main()
{
f >> n;
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
f >> mat[i][j];
if (mat[i][j]==0) {
mat[i][j]=oo;
}
}
}
for (int k=1;k<=n;k++) {
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
if (mat[i][j] > mat[i][k] + mat[k][j] && i!=j && i!=k && k!=j) {
mat[i][j] = mat[i][k] + mat[k][j];
}
}
}
}
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
if (mat[i][j]==oo) {
g << 0 << " ";
}
else {
g<<mat[i][j]<<" ";
}
}
g<<'\n';
}
return 0;
}