Pagini recente » Cod sursa (job #2090704) | Cod sursa (job #2071973) | Cod sursa (job #2248042) | Cod sursa (job #842730) | Cod sursa (job #2424489)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
const int kInf = 1e9;
int main() {
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n; cin >> n;
vector<vector<int>> d(n, vector<int> (n, 0));
for(int i = 0; i < n; i += 1) {
for(int j = 0; j < n; j += 1) {
cin >> d[i][j];
if(d[i][j] == 0 and i != j) {
d[i][j] = kInf;
}
}
}
for(int k = 0; k < n; k += 1)
for(int i = 0; i < n; i += 1)
for(int j = 0; j < n; j += 1) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
for(int i = 0; i < n; i += 1) {
for(int j = 0; j < n; j += 1) {
cout << d[i][j] << " ";
}
cout << "\n";
}
}