Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int maxV = 1000;
- int GR[maxV][maxV];
- //алгоритм Флойда-Уоршелла
- void FU(int D[][maxV], int V)
- {
- for (int i = 0; i < V; i++) D[i][i] = 0;
- for (int k = 0; k < V; k++)
- for (int i = 0; i < V; i++)
- for (int j = 0; j < V; j++)
- if (D[i][k] && D[k][j] && i != j)
- if (D[i][k] + D[k][j] < D[i][j] || D[i][j] == 0)
- D[i][j] = D[i][k] + D[k][j];
- for (int i = 0; i < V; i++)
- {
- for (int j = 0; j < V; j++)
- cout << D[i][j] << "\t";
- cout << endl;
- }
- }
- //главная функция
- int main()
- {
- setlocale(LC_ALL, "Rus");
- int n;
- cout << "Количество вершин в графе > ";
- cin >> n;
- cout << "Введите матрицу весов ребер:\n";
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- cout << "GR[" << i + 1 << "][" << j + 1 << "] > ";
- cin >> GR[i][j];
- }
- cout << "Матрица кратчайших путей:" << endl;
- FU(GR, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment