Pagini recente » Cod sursa (job #2083471) | Cod sursa (job #336520) | Cod sursa (job #1269807) | Cod sursa (job #1808335) | Cod sursa (job #2611436)
#include <bits/stdc++.h>
using namespace std;
#define NMAX 109
class Task {
public:
void solve() {
read_input();
get_result();
print_output();
}
private:
int n;
int dist[NMAX][NMAX];
void read_input() {
ifstream fin("royfloyd.in");
fin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
fin >> dist[i][j];
}
}
fin.close();
}
void get_result() {
for (int k = 1; k <= n; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (i != j)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
}
void print_output() {
ofstream fout("royfloyd.out");
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j)
fout << dist[i][j] << ' ';
fout << endl;
}
fout.close();
}
};
// Please always keep this simple main function!
int main() {
// Allocate a Task object on heap in order to be able to
// declare huge static-allocated data structures inside the class.
Task *task = new Task();
task->solve();
delete task;
return 0;
}