Advertisement
Saleh127

UVA 11396

Aug 9th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. vector<ll>g[200005];
  6. bool v[200005];
  7. ll col[200005];
  8. ll ans=0;
  9.  
  10. void dfs(ll in)
  11. {
  12. v[in]=1;
  13. for(auto c:g[in])
  14. {
  15. if(col[c]==col[in])
  16. {
  17. ans=1;
  18. return;
  19. }
  20. if(v[c]==0)
  21. {
  22. if(col[in]==1) col[c]=2;
  23. else if(col[in]==2) col[c]=1;
  24.  
  25. dfs(c);
  26. }
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. ios_base::sync_with_stdio(0);
  33. cin.tie(0);cout.tie(0);
  34.  
  35. ll n,m,i,j,k,l;
  36.  
  37. while(cin>>n && n)
  38. {
  39. while(cin>>j>>k && (j+k)>0)
  40. {
  41. g[j].push_back(k);
  42. g[k].push_back(j);
  43. }
  44. col[1]=1;
  45. dfs(1);
  46.  
  47. if(ans) cout<<"NO"<<endl;
  48. else cout<<"YES"<<endl;
  49.  
  50. ans=0;
  51. for(i=0;i<n+4;i++)
  52. {
  53. g[i].clear();
  54. col[i]=0;
  55. v[i]=0;
  56. }
  57. }
  58.  
  59.  
  60. return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement