Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- const int INT = 10000000;
- class Graph
- {
- private:
- bool orient;
- int n, **arr, shet_reber, **d;
- public:
- Graph (int **matrix, int x, int shet)
- {
- n = x;
- arr = matrix;
- d = matrix;
- shet_reber = shet;
- }
- void minpath();
- int get_length_path(int x, int y);
- };
- void Graph::minpath()
- {
- for (int l = 0; l < n; l++)
- for (int i = 0; i < n; i++)
- if (d[i][l] < INT)
- for (int j = 0; j < n; j++)
- d[i][j] = min(d[i][j], d[i][l] + d[l][j]);
- }
- int Graph::get_length_path(int x, int y)
- {
- int dlina = 0;
- minpath();
- if (d[x][y] == INT)
- dlina = -1;
- else dlina = d[x][y];
- return dlina;
- }
- int main()
- {
- int n, shet_reber = 0, x, y;
- cin >> n >> x >> y;
- int **arr = new int*[n];
- for ( int i = 0; i < n; i++)
- arr[i] = new int[n];
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- cin >> arr[i][j];
- if (arr[i][j] == -1)
- arr[i][j] = INT;
- shet_reber++;
- }
- Graph object(arr, n, shet_reber);
- cout << object.get_length_path(x-1, y-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement