Cod sursa(job #2815058)
Utilizator | Data | 9 decembrie 2021 00:56:20 | |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 20 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int a[101][101], n;
int main() {
f >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
f >> a[i][j];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
if((a[i][j]>a[i][k]+a[k][j] || !a[i][j]) && a[i][k] && a[k][j] && i!=j)
a[i][j]=a[i][k]+a[k][j];
for(int i = 0 ; i < n ;++i)
{
for(int j = 0 ; j < n ;++j)
g<<a[i][j]<<" ";
g<<'\n';
}
return 0;
}