Pagini recente » Cod sursa (job #2044101) | Cod sursa (job #2302644) | Cod sursa (job #2080928) | Cod sursa (job #1526147) | Cod sursa (job #812612)
Cod sursa(job #812612)
#include<iostream>
#include<fstream>
using namespace std;
#define MAX_N 100
int N, a[MAX_N][MAX_N];
void read(){
ifstream f("royfloyd.in");
f >> N;
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
f >> a[i][j];
}
}
}
void solve(){
for(int k=1; k<=N; k++){
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
if(a[i][k]!=0 && a[k][j] !=0)
if(a[i][j] > a[i][k] + a[k][j])
a[i][j] = a[i][k]+ a[k][j];
}
}
}
}
void write(){
ofstream g("royfloyd.out");
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
if(i!=j)
g << a[i][j] << " ";
else g << "0 ";
}
g << endl;
}
}
int main(){
read();
solve();
write();
return 0;
}