Advertisement
haufont

Untitled

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