fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ii pair<int, int>
  4. #define ll pair<long long, long long>
  5. const int inf = 1e9;
  6. const int mod = 1e9 +7;
  7. const int maxn = 1e5 + 1;
  8. int t,m,n,a[maxn],u,v;
  9. vector<int> g[maxn];
  10. bool kiemtra(int n)
  11. {
  12. for (int i=1; i<=n; i++) a[i]=-1;
  13. for (int i=1; i<=n; i++)
  14. if (a[i]==-1)
  15. {
  16. queue<int> q;
  17. q.push(i);
  18. a[i]=0;
  19. while (!q.empty())
  20. {
  21. int u=q.front(); q.pop();
  22. for (int v:g[u])
  23. if (a[v]==-1) a[v]=1-a[u],q.push(v);
  24. else if (a[v]==a[u]) return false;
  25. }
  26. }
  27. return true;
  28. }
  29. int main(){
  30. ios_base::sync_with_stdio(false);
  31. cin.tie(0); cout.tie(0);
  32. cin>>t;
  33. while (t--)
  34. {
  35. cin>>n>>m;
  36. for (int i=1; i<=n; i++) g[i].clear();
  37. for (int i=1; i<=m; i++)
  38. {
  39. cin>>u>>v;
  40. g[u].push_back(v);
  41. g[v].push_back(u);
  42. }
  43. if (kiemtra(n)) cout<<"NO";
  44. else cout<<"YES";
  45. cout<<"\n";
  46. }
  47. }
  48.  
Success #stdin #stdout 0.01s 5928KB
stdin
Standard input is empty
stdout
Standard output is empty