Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5. int n, m, v, u ,k;
  6. vector<pair<int,int>> raspopov_loh_kek_cheburek;
  7. vector<vector<int>> graf;
  8. set<int> bin;
  9. vector<int> gleb_kakaha_azazazaza;
  10.  
  11. void dfs(int v, int par){
  12.     gleb_kakaha_azazazaza[v] = 1;
  13.     for (int u: graf[v]){
  14.         if (!gleb_kakaha_azazazaza[u]){
  15.             dfs(u,v);
  16.         }
  17.     }
  18. }
  19. int main(){
  20.     cin >> n >> m >> v >> u;
  21.     for (int i = 0; i < m; ++i){
  22.         int left, right;
  23.         cin >> left >> right;
  24.         left--;
  25.         right--;
  26.         raspopov_loh_kek_cheburek.push_back({left, right});
  27.     }
  28.     cin >> k;
  29.     for (int i = 0; i < k; ++i){
  30.         int tmp;
  31.         cin >> tmp;
  32.         bin.insert(tmp - 1);
  33.     }
  34.     for (int i = 0; i < raspopov_loh_kek_cheburek.size(); ++i){
  35.         if (bin.count(raspopov_loh_kek_cheburek[i].first) || bin.count(raspopov_loh_kek_cheburek[i].second)){
  36.             raspopov_loh_kek_cheburek[i] = {-1,-1};
  37.         }
  38.     }
  39.     graf.resize(n);
  40.     for (auto elem: raspopov_loh_kek_cheburek){
  41.         if (elem.first != -1){
  42.             int a = elem.first;
  43.             int b = elem.second;
  44.             graf[a].push_back(b);
  45.             graf[b].push_back(a);
  46.         }
  47.     }
  48.     gleb_kakaha_azazazaza.resize(n);
  49.     dfs(v - 1, 0);
  50.     if (gleb_kakaha_azazazaza[u - 1]){
  51.         cout << "YES";
  52.     }
  53.     else{
  54.         cout << "NO";
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement