Pagini recente » Cod sursa (job #2116408) | Cod sursa (job #2911647) | Cod sursa (job #1379625) | Cod sursa (job #3217380) | Cod sursa (job #1830520)
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int N = 105;
const int oo = (1 << 29);
int cost[N][N];
int n, k, i, j;
int main() {
f >> n;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
f >> cost[i][j];
if(!cost[i][j]) cost[i][j] = oo;
}
for(k = 1; k <= n; k++)
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
if(i != j && i != k && j != k)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
for(i = 1; i <= n; i++, g << '\n')
for(j = 1; j <= n; j++) {
if(cost[i][j] == oo) cost[i][j] = 0;
g << cost[i][j] << '\n';
}
return 0;
}