Pagini recente » Cod sursa (job #3256487) | Cod sursa (job #1438907) | Cod sursa (job #1789360) | Cod sursa (job #1396127) | Cod sursa (job #1492071)
#include <fstream>
#include <vector>
using namespace std;
int main() {
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n;
cin >> n;
vector< vector<int> > cost(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> cost[i][j];
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
if (i == k || !cost[i][k]) continue;
for (int j = 0; j < n; j++) {
if (i != j && j != k && cost[i][j] > cost[i][k] + cost[k][j] && cost[k][j]) {
cost[i][j] = cost[i][k] + cost[k][j];
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << cost[i][j] << " ";
}
cout << "\n";
}
}