Pagini recente » Cod sursa (job #3249208) | Cod sursa (job #1990767) | Cod sursa (job #245304) | Cod sursa (job #246872) | Cod sursa (job #3334798)
#include <iostream>
#include <random>
#include <fstream>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int mat[105][105];
int main() {
int n;
fin>>n;
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++) {
int x;
fin>>x;
if (x==0)
mat[i][j]=2e9;
else
mat[i][j]=x;
}
for (int k=1; k<=n; k++)
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
if (i!=j and mat[i][k]+mat[k][j]<mat[i][j])
mat[i][j]=mat[i][k]+mat[k][j];
for (int i=1; i<=n; i++,fout<<"\n")
for (int j=1; j<=n; j++)
if (mat[i][j]!=2e9)
fout<<mat[i][j]<<' ';
else
fout<<0<<' ';
return 0;
}
// num=10,/=11,*=12,-=13,+=14,enter=15,.=16,