Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #2510131)
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
void roy(int adjMatrix[101][101],int n) {
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
adjMatrix[i][j] = min(adjMatrix[i][j], adjMatrix[i][k]+ adjMatrix[k][j]);
}
#define inf 1000000007
int main() {
int adjMatrix[101][101];
int numVertex; in >> numVertex;
for (int i = 0; i < numVertex; i++) {
for (int j = 0; j < numVertex; j++) {
in >> adjMatrix[i][j];
}
}
roy(adjMatrix,numVertex);
for (int i = 0; i < numVertex; i++) {
for (int j = 0; j < numVertex; j++)
out << adjMatrix[i][j] << ' ';
out << endl;
}
}
/*
6 5
0 1 10
0 4 20
1 2 30
1 3 40
1 5 50
2 3 60
3 4 70
*/