Pagini recente » Cod sursa (job #2522838) | Cod sursa (job #2246481) | Cod sursa (job #2277999) | Cod sursa (job #3003605) | Cod sursa (job #1830506)
#include <fstream>
#include <vector>
#define pb push_back
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int N = 105;
const int oo = (1 << 30);
int d[N], 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 && j != k && k != i)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++)
g << (cost[i][j] == oo ? 0 : cost[i][j]) << ' ';
g << '\n';
}
return 0;
}