Pagini recente » Cod sursa (job #2073393) | Cod sursa (job #2063052) | Cod sursa (job #2272077) | Cod sursa (job #2235230) | Cod sursa (job #2725832)
#include <fstream>
#include <vector>
using namespace std;
int main() {
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
fin >> n;
constexpr auto kInf = 1 << 30;
vector<vector<int>> cost(n, vector<int>(n));
for (auto& row : cost) {
for (auto& c : row) {
fin >> c;
if (c == 0) {
c = kInf;
}
}
}
for (auto k = 0; k < n; k += 1) {
for (auto i = 0; i < n; i += 1) {
for (auto j = 0; j < n; j += 1) {
if (i != j && i != k && j != k) {
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
}
for (const auto& row : cost) {
for (const auto& c : row) {
fout << (c < kInf ? c : 0) << " ";
}
fout << "\n";
}
return 0;
}