Pagini recente » Cod sursa (job #2331598) | Cod sursa (job #468029) | Cod sursa (job #913944) | Cod sursa (job #1244360) | Cod sursa (job #2067424)
#include <fstream>
#include <vector>
using namespace std;
int main() {
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n;
in >> n;
vector< vector<int> > graph (n, vector<int> (n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
in >> graph[i][j];
}
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j && graph[i][k] && graph[k][j] && (graph[i][j] > graph[i][k] + graph[k][j] || ! graph[i][j])) {
graph [i][j] = graph[i][k] + graph[k][j];
}
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
out << graph[i][j] << " ";
}
out << '\n';
}
return 0;
}