bhupixb

Euler tour

Jul 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. /*
  2. I am Hunting High and Low
  3. Diving from the sky above
  4. Looking for, more and more, once again
  5. I'm Hunting High and Low
  6. Sometimes I may win, sometimes I'll lose
  7. It's just a game that I play
  8.  
  9. After the storm there's a calm
  10. Through the clouds shines a ray of the sun
  11. I'm carried from all my harm
  12. There is no one I can't outrun
  13.  
  14. Now I'm leaving my worries behind
  15. Feel the freedom of body and mind
  16. I'm starting my journey, I'm drifting away with the wind, I go___________________:-
  17. */
  18.  
  19. #include <bits/stdc++.h>
  20. using namespace std;
  21. typedef long long ll;
  22. const int N = 100+7;
  23. vector < int > v[N], euler;
  24. int vis[N];
  25. void dfs(int node){
  26. vis[node] = 1;
  27. euler.push_back(node);
  28. for(auto i : v[node]){
  29. if(!vis[i]){
  30. dfs(i);
  31. euler.push_back(node);
  32. }
  33. }
  34. }
  35.  
  36. int main(){
  37. ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  38. int n, i, q, l, r;
  39. cin >> n >> q;
  40. for(i = 1; i <= q; i++){
  41. cin >> l >> r;
  42. v[l].push_back(r);
  43. v[r].push_back(l);
  44. }
  45. dfs(1);
  46. for(int x : euler)cout << x << ' ';
  47.  
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment