Pagini recente » Cod sursa (job #426882) | Cod sursa (job #2980549) | Cod sursa (job #2677656) | Cod sursa (job #793539) | Cod sursa (job #2815051)
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int main() {
int a[101][101], n, b[101][101];
f >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
f >> a[i][j];
b[i][j] = a[i][j];
}
b[i][i] = 0;
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
if(b[i][j]>b[i][k]+b[k][j])
b[i][j]=b[i][k]+b[k][j];
for(int i = 0 ; i < n ;++i)
{
for(int j = 0 ; j < n ;++j)
g<<b[i][j]<<" ";
g<<'\n';
}
return 0;
}