Pagini recente » Cod sursa (job #3199276) | Cod sursa (job #2123762) | Cod sursa (job #1406131) | Cod sursa (job #2174722) | Cod sursa (job #3197000)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int main()
{
int n;
fin >> n;
vector<vector<long long>> v(n + 1, vector<long long>(n + 1));
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
fin >> v[i][j];
if(i != j && v[i][j] == 0)
v[i][j] = INT_MAX;
}
}
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(i != j)
{
v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
}
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
fout << v[i][j] << " ";
}
fout << "\n";
}
return 0;
}