Pagini recente » Cod sursa (job #3353061) | Cod sursa (job #1011415) | Cod sursa (job #2948198) | Cod sursa (job #1048131) | Cod sursa (job #3354141)
#include <fstream>
#include <vector>
using namespace std;
const int INF = 1e9;
int main() {
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
fin >> n;
vector <vector <int> > c(n + 1, vector <int> (n + 1, INF));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int aux;
fin >> aux;
if (i != j && aux == 0) {
aux = INF;
}
c[i][j] = aux;
}
}
fin.close();
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (c[i][k] + c[k][j] < c[i][j]) {
c[i][j] = c[i][k] + c[k][j];
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i != j && c[i][j] == INF) {
c[i][j] = 0;
}
fout << c[i][j] << " ";
}
fout << "\n";
}
fout.close();
return 0;
}