Pagini recente » Cod sursa (job #2137074) | Cod sursa (job #264056) | Cod sursa (job #1815832) | Cod sursa (job #2945591) | Cod sursa (job #689544)
Cod sursa(job #689544)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
vector< vector<int> > matAdi;
int main (int argc, char const *argv[])
{
ifstream in ("royfloyd.in");
in >> n;
matAdi.resize(n, vector<int>(n));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
in >> matAdi[i][j];
}
in.close();
/*
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << matAdi[i][j] << ' ';
cout << '\n';
}
*/
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j)
matAdi[i][j] = min (matAdi[i][j], (matAdi[i][k] + matAdi[k][j]));
ofstream out ("royfloyd.out");
/*
if (a[i][k] &&
a[k][j] &&
(a[i][j] > a[i][k] + a[k][j] || !a[i][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++)
out << matAdi[i][j] << ' ';
out << '\n';
}
out.close();
return 0;
}