Pagini recente » Cod sursa (job #113430) | Cod sursa (job #1138455) | Cod sursa (job #1594048) | Cod sursa (job #2012842) | Cod sursa (job #2508664)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
void FloydWarshall(int n, vector <vector<int>> graph)
{
vector <vector<int>> dist(n, vector<int>(n));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
dist[i][j] = graph[i][j];
}
}
for (int k = 0; k < n; k++)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (dist[i][k] + dist[k][j] < dist[i][j])
{
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << dist[i][j] << " ";
}
cout << "\n";
}
}
int main()
{
int n, weight;
cin >> n;
vector <vector<int>> graph(n, vector<int> (n) );
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n;j++)
{
cin >> weight;
graph[i][j] = weight;
}
}
FloydWarshall(n, graph);
}