Pagini recente » Borderou de evaluare (job #2649093) | Borderou de evaluare (job #3147265) | Borderou de evaluare (job #1177981) | Borderou de evaluare (job #492096) | Cod sursa (job #1609618)
#include <fstream>
using namespace std;
int dist[101][101], n;
void read()
{
ifstream fin("royfloyd.in");
fin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
fin >> dist[i][j];
}
fin.close();
}
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 && dist[i][k] * dist[k][j])
if(dist[i][j] > dist[i][k] + dist[k][j] || !dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
void write()
{
ofstream fout("royfloyd.out");
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
fout << dist[i][j] << " ";
fout << "\n";
}
fout.close();
}
int main()
{
read();
royfloyd();
write();
return 0;
}