Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1.  
  2. #define _GLIBCXX_DEBUG
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int v, e;
  9. vector<vector<int>> g(v + 10);
  10. vector<bool> col(v + 10, 0);
  11. int countt = 0;
  12.  
  13. void dfs(int u){
  14. if (col[u]){
  15. return;
  16. }
  17. col[u] = 1;
  18. countt++;
  19. for(int i = 0; i < g[u].size(); i++){
  20. dfs(g[u][i]);
  21. }
  22. }
  23.  
  24. int main(){
  25. cin >> v >> e;
  26. if (e != v - 1){
  27. cout << "NO" << '\n';
  28. return 0;
  29. }
  30. for(int i = 0; i < e; i++){
  31. int a, b;
  32. cin >> a >> b;
  33. a--;
  34. b--;
  35. g[a].push_back(b);
  36. g[b].push_back(a);
  37. }
  38. dfs(0);
  39. if (countt == v){
  40. cout << "YES" << '\n';
  41. }
  42. else{
  43. cout << "NO" << '\n';
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement