Pagini recente » Cod sursa (job #2521864) | Diferente pentru info-oltenia-2018/individual/9 intre reviziile 2 si 3 | Monitorul de evaluare | Cod sursa (job #2017042) | Cod sursa (job #2859098)
#include <fstream>
#include <algorithm>
std::ifstream in("royfloyd.in");
std::ofstream out("royfloyd.out");
constexpr int N = 101;
constexpr int INF = 1e5+1;
int cost[N][N], n;
void royfloyd(){
for(int k=0; k<n; ++k) for(int i=0; i<n; ++i) for(int j=0; j<n; ++j)
if(cost[i][k] + cost[k][j] < cost[i][j]) cost[i][j] = cost[i][k] + cost[k][j];
}
int main(){
in >> n;
for(int i=0; i<n; ++i) for(int j=0; j<n; ++j){
in >> cost[i][j];
if(i!=j && !cost[i][j]) cost[i][j] = INF;
}
royfloyd();
for(int i=0; i<n; ++i){
for(int j=0; j<n; ++j)
out << cost[i][j] << ' ';
out << '\n';
}
return 0;
}