Pagini recente » Cod sursa (job #2582785) | Cod sursa (job #2174779) | Cod sursa (job #1350320) | Cod sursa (job #1016247) | Cod sursa (job #1626192)
#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 k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j) {
if(i != j && m[i][k] && m[k][j])
if(m[i][k] + m[k][j] < m[i][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";
}
}