fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n,e,u,v;
  6.  
  7. set < int > myset[100005];
  8.  
  9. stack < int > temp_path;
  10.  
  11. vector < int > vec(100005);
  12.  
  13. bool chk_euler()
  14. {
  15. for(int i=1;i<=n;i++)
  16. {
  17. if((myset[i].size()&1)) return 0;
  18. }
  19.  
  20. return 1;
  21. }
  22.  
  23. bool euler_dfs(int ref)
  24. {
  25. temp_path.push(ref);
  26.  
  27. set < int >::iterator it;
  28.  
  29. int k=e;
  30.  
  31. while(!temp_path.empty())
  32. {
  33. int ver=temp_path.top();
  34.  
  35. if(myset[ver].size()!=0)
  36. {
  37. it=myset[ver].begin();
  38.  
  39. myset[ver].erase(*it);
  40.  
  41. myset[*it].erase(ver);
  42.  
  43. temp_path.push(*it);
  44. }
  45.  
  46. else
  47. {
  48. vec[k]=ver; k--;
  49.  
  50. temp_path.pop();
  51. }
  52. }
  53.  
  54. cout<<"YES\n";
  55.  
  56. for(int i=0;i<e;i++)
  57. {
  58. cout<<vec[i]<<" "<<vec[i+1]<<"\n";
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. ios_base::sync_with_stdio(false);
  65.  
  66. cin.tie(NULL);
  67.  
  68. cin>>n>>e;
  69.  
  70. int ref;
  71.  
  72. for(int i=0;i<e;i++)
  73. {
  74. cin>>u>>v;
  75.  
  76. if(i==0) ref=u;
  77.  
  78. myset[u].insert(v);
  79.  
  80. myset[v].insert(u);
  81. }
  82.  
  83. if(chk_euler())
  84. {
  85. euler_dfs(ref);
  86. }
  87.  
  88. else cout<<"NO\n";
  89.  
  90. return 0;
  91. }
Success #stdin #stdout 0s 19936KB
stdin
Standard input is empty
stdout
YES