Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ld long double
- #define pi pair<int, int>
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- #define PI acos(-1.0)
- #define N 1000000
- using namespace std;
- ll t,n ,m , a, b;
- bool vis[200200], ans;
- vector<vector<int>> G;
- bool DFS(int u){
- vis[u] = true;
- int cnt = 0;
- for (auto i : G[u])
- if (vis[i]) cnt++;
- else return DFS(i);
- if (cnt > 1) return false;
- return true;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- cin >> t;
- while(t--){
- cin >> n >> m;
- G.resize(n+1);
- G.clear();
- for (int i=0; i<m; i++){
- cin >> a >> b;
- G[a].pb(b);
- G[b].pb(a);
- }
- memset(vis, false, sizeof vis);
- ans = DFS(1);
- cout << (ans ? "Yes" : "No") << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement