Pagini recente » Cod sursa (job #2243253) | Cod sursa (job #2245942) | Cod sursa (job #2315758) | Cod sursa (job #2129855) | Cod sursa (job #3198029)
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int INF = 1e9;
int n, dist[101][101];
int main() {
f >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) {
int x; f >> x;
dist[i][j] = (x == 0 && i != j) ? INF : x;
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(dist[i][j] > dist[i][k] + dist[k][j])
dist[i][j] = dist[i][k] + dist[k][j];
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
g << ((dist[i][j] != INF) ? dist[i][j] : 0) << ' ';
g << '\n';
}
return 0;
}