Pagini recente » Cod sursa (job #3198926) | Cod sursa (job #2820810) | Cod sursa (job #2761737) | Cod sursa (job #30944) | Cod sursa (job #1626185)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int m[101][101];
int main() {
int n;
fin >> n;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
fin >> m[i][j];
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
for(int k = 0; k < n; ++k) {
if(i != j)
if(m[i][k] + m[k][j] < m[i][j])
m[i][j] = m[i][k] + m[k][j];
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j)
fout << m[i][j] << " ";
fout << "\n";
}
}