Advertisement
haufont

Untitled

Jun 14th, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include<vector>
  2. #include<iostream>
  3. using namespace std;
  4. bool used[100113];
  5. vector<int>gr[100113];
  6. int pr[100113];
  7. bool x = false;
  8. int k;
  9. bool dfs(int v, int p)
  10. {
  11.     bool fl = false;
  12.     used[v] = 1; pr[v] = p;
  13.     for (int i = 0; i < gr[v].size(); i++)
  14.     {
  15.         if (v == k)
  16.         {
  17.             return true;
  18.         }
  19.         if ((!used[gr[v][i]]))
  20.         {
  21.             fl = dfs(gr[v][i], v);
  22.         }
  23.     }
  24.     return fl;
  25. }
  26. int main()
  27. {
  28.     int a, b;
  29.     cin >> a >> b >> k;
  30.     int h1, h2;
  31.     for (int i = 0; i < b; i++)
  32.     {
  33.         cin >> h1 >> h2;
  34.         gr[h1].push_back(h2);
  35.         gr[h2].push_back(h1);
  36.     }
  37.     bool z1 = dfs(1, 0);
  38.     used[0] = 0;
  39.     bool z2 = dfs(1, 0);
  40.     if (z1 && z2)
  41.     {
  42.         cout << "YES";
  43.     }
  44.     else
  45.     {
  46.         cout << "NO";
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement