Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- #define N 101
- vector <int> mas[N];
- int res[N];
- int used[N];
- int n;
- void bfs(int start, int finish) {
- queue <int> q;
- q.push(start);
- used[start] = 1;
- while (q.size() != 0) {
- start = q.front();
- q.pop();
- for (int i = 0; i < n; i++) {
- if (used[i] == 0 && mas[start][i] != -1) {
- q.push(i);
- used[i] = 1;
- }
- int per = res[start] + mas[start][i];
- if (res[i] != 0 && res[i] > per) {
- res[i] = per;
- }
- }
- }
- }
- int main() {
- int start, finish;
- cin >> n >> start >> finish;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- int x;
- cin >> x;
- mas[i].push_back(x);
- }
- }
- for (int i = 0; i < n; i++) res[i] = 1000000;
- res[start - 1] = 0;
- (start - 1, finish - 1);
- int way = res[finish - 1];
- if (way != 1000000) cout << way;
- else cout << "-1";
- return 0;
- }
Add Comment
Please, Sign In to add comment