fork download
  1. /// euler's cycle - muoii
  2.  
  3. /// vn.spoj.com/problems/NKPOS/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define tag "spoj"
  8. #define maxn 207
  9. #define maxc 207
  10. #define oo 1000000007
  11. #define mid ((l+r)>>1)
  12. #define meset(a,x) memset(a,x,sizeof(a))
  13. #define loop(x) for(int LoOpEr=x;LoOpEr-->0;)
  14. ///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  15. int n,m;
  16. int c[maxn][maxn];
  17. void euler_tour()
  18. {
  19. cout<<m<<"\n";
  20. stack<int> stak;
  21. stak.push(1);
  22.  
  23. int u,v;
  24. while(stak.size())
  25. {
  26. u=stak.top();
  27.  
  28. for(v=1;v<=n;v++)
  29. if(c[u][v])
  30. {
  31. stak.push(v);
  32. --c[u][v];
  33. --c[v][u];
  34. break;
  35. }
  36.  
  37. if(v>n)
  38. {
  39. cout<<u<<" ";
  40. stak.pop();
  41. }
  42. }
  43. }
  44.  
  45. int main()
  46. {
  47. #ifdef dmdd
  48. freopen(tag".inp","r",stdin); freopen(tag".out","w",stdout);
  49. #endif // dmdd
  50. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  51.  
  52. cin>>n>>m;
  53.  
  54. int x,y;
  55. loop(n) cin>>x;
  56. loop(m) cin>>x>>y,++c[x][y],++c[y][x];
  57.  
  58. euler_tour();
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 15408KB
stdin
6 7
1
7
4
10
20
5
2 4
1 5
2 1
4 5
3 6
1 6
1 3
stdout
7
1 6 3 1 5 4 2 1