Cod sursa(job #2480382)
| Utilizator | Data | 25 octombrie 2019 14:42:57 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include<fstream>
#define MAX 101
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int a[MAX][MAX],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 k = 0; k < n; ++k)
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (a[i][j] > a[i][k] + a[k][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';
}
}