Pagini recente » Cod sursa (job #1441983) | Cod sursa (job #2586016) | Cod sursa (job #2406224) | Cod sursa (job #2399655) | Cod sursa (job #2972269)
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
#define NMAX 101
#define INF 0x3f3f3f3f
int n, a[NMAX][NMAX];
int main() {
fin >> n;
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= n; ++ j)
fin >> a[i][j];
for (int k = 1; k <= n; ++ k)
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= n; ++ j)
if (a[i][j] > a[i][k] + a[k][j])
a[i][j] = a[i][k] + a[k][j];
for (int i = 1; i <= n; ++ i, fout << '\n')
for (int j = 1; j <= n; ++ j)
fout << a[i][j] << ' ';
return 0;
}