Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdafx.h"
  3. #include "stdio.h"
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7. #include <algorithm>
  8. #include <set>
  9.  
  10.  
  11. using namespace std;
  12. void dfs(int &v, vector<vector<int>> &a, vector<bool> &used, int &cnt)
  13. {
  14. used[v] = true;
  15. cnt++;
  16. for (int i = 0; i < a[v].size(); ++i)
  17. if (!used[a[v][i]])
  18. dfs(a[v][i], a, used, cnt);
  19. }
  20. void main()
  21. {
  22. #ifdef _DEBUG
  23. freopen("input.txt", "r", stdin);
  24. freopen("output.txt", "w", stdout);
  25. #endif
  26. int n, m, cnt, flag = 1;
  27. cin >> n >> m;
  28. vector<vector<int>> a (n);
  29. vector<bool> used(n);
  30. for (int i = 0; i < m; ++i)
  31. {
  32. int ch, ch1;
  33. ch--, ch1--;
  34. a[ch].push_back(ch1);
  35. a[ch1].push_back(ch);
  36. }
  37. for (int i = 0; i < n; ++i)
  38. if (!used[i])
  39. {
  40. dfs(i, a, used, cnt = -1);
  41. if (a[i].size() == cnt)
  42. flag *= 1;
  43. else
  44. flag *= 0;
  45. }
  46. if (flag == 1)
  47. cout << "YES";
  48. else
  49. cout << "NO";
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement