Pagini recente » Cod sursa (job #1196413) | Cod sursa (job #51097) | Cod sursa (job #829928) | Cod sursa (job #2281) | Cod sursa (job #1757549)
#include <bits/stdc++.h>
#define ll long long
#define lli long long int
#define endl "\n"
#include <stdio.h>
using namespace std;
int cost[300][300];
int n;
void RoyFloyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j && cost[i][k] != 0 && cost[k][j] !=0 && (cost[i][j] >= cost[i][k] + cost[k][j] || cost[i][j] == 0))
{
cost[i][j] = cost[i][k] + cost[k][j];
}
}
int main()
{
ios_base::sync_with_stdio(false);
ifstream fin("royfloyd.in");
ofstream fou("royfloyd.out");
fin >> n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fin >> cost[i][j];
}
RoyFloyd();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
fou << cost[i][j] << ' ';
fou << endl;
}
return (0);
}