Pagini recente » Cod sursa (job #595237) | Cod sursa (job #951204) | Cod sursa (job #1414268) | Cod sursa (job #1980840) | Cod sursa (job #3202241)
#include <fstream>
using namespace std;
const int INF = 1000;
ifstream cin("alg.in");
ofstream cout("alg.out");
void Floyd(int a[][100], int n){
int dist[n][n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
dist[i][j] = a[i][j];
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(dist[i][k] != INF && dist[k][j] != INF && dist[i][k] + dist[k][j] < dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++)
cout << dist[i][j] << " ";
cout << '\n';
}
}
int main(){
int n;
cin >> n;
int a[100][100];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> a[i][j];
if(a[i][j] == 0 && i != j)
a[i][j] = INF;
}
}
Floyd(a, n);
return 0;
}