fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool can;
  4. int color[100000];
  5. vector<int>graf[100000];
  6. void dfs(int u, int c)
  7. {
  8. //color[u]=c;
  9. // c^=1;
  10.  
  11. if(color[u]>-1)
  12. {
  13. if(color[u]!=c)
  14. {
  15. can=false;
  16. }
  17. return;
  18. }
  19. color[u]=c;
  20. //c^=1;
  21. for(auto x: graf[u])
  22.  
  23. {
  24. dfs(x,c^1);
  25. }
  26.  
  27.  
  28.  
  29.  
  30. }
  31. int main()
  32. {
  33. int n,e; cin>>n>>e;
  34. vector<pair<int,int>>edges;
  35. can=true;
  36. memset(color,-1,sizeof(color));
  37. for(int i=0;i<e;i++)
  38. {
  39. int x,y; cin>>x>>y;
  40. graf[x].push_back(y);
  41. graf[y].push_back(x);
  42. edges.push_back({x,y});
  43. }
  44. dfs(1,1);
  45. if(!can){cout<<"NO";}
  46. else {cout<<"YES\n";}
  47. for(int i=0;i<e;i++)
  48. {
  49. int x=edges[i].first;
  50. int y=edges[i].second;
  51. if(color[x]==1)
  52. {
  53. cout<<1;
  54. }
  55. else
  56. {
  57. cout<<0;
  58. }
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
Success #stdin #stdout 0s 6280KB
stdin
6 5
1 5
2 1
1 4
3 1
6 1
stdout
YES
10100