Pagini recente » Cod sursa (job #218592) | Cod sursa (job #951521) | Cod sursa (job #499529) | Cod sursa (job #938886) | Cod sursa (job #2422156)
#include <iostream>
#include <vector>
#include<fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int N = 101;
int n;
int W[N][N];
int D[N][N];
void citire()
{
f >> n;
for(int i=1;i<=n;i++)
for (int j = 1; j <= n; j++)
{
int y;
f >> y;
W[i][j] = y;
D[i][j] = y;
}
}
int main()
{
citire();
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if (D[i][j] > D[i][k] + D[k][j])
{
D[i][j] = D[i][k] + D[k][j];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
g << D[i][j] << " ";
g << "\n";
}
return 0;
}