Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define pi pair<int, int>
  5. #define F first
  6. #define S second
  7. #define pb push_back
  8. #define mp make_pair
  9. #define PI acos(-1.0)
  10. #define N 1000000
  11. using namespace std;
  12. ll t,n ,m , a, b;
  13. bool vis[200200], ans;
  14. vector<vector<int>> G;
  15.  
  16. bool DFS(int u){
  17. vis[u] = true;
  18.  
  19. int cnt = 0;
  20. for (auto i : G[u])
  21. if (vis[i]) cnt++;
  22. else return DFS(i);
  23.  
  24. if (cnt > 1) return false;
  25. return true;
  26. }
  27.  
  28. int main()
  29. {
  30. ios::sync_with_stdio(0);
  31. cin.tie(0); cout.tie(0);
  32. cin >> t;
  33. while(t--){
  34. cin >> n >> m;
  35. G.resize(n+1);
  36. G.clear();
  37. for (int i=0; i<m; i++){
  38. cin >> a >> b;
  39. G[a].pb(b);
  40. G[b].pb(a);
  41. }
  42. memset(vis, false, sizeof vis);
  43. ans = DFS(1);
  44. cout << (ans ? "Yes" : "No") << '\n';
  45. }
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement