Pagini recente » Istoria paginii runda/my_cex/clasament | Istoria paginii runda/test1.-q/clasament | Cod sursa (job #340844) | Istoria paginii runda/proges/clasament | Cod sursa (job #2748564)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int a[101][101], n;
void read() {
f >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
f >> a[i][j];
}
void solve() {
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];
}
void print() {
for(int i = 1; i <= n; ++i, g << '\n')
for(int j = 1; j <= n; ++j)
g << a[i][j] << " ";
}
int main()
{
read();
solve();
print();
}