Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cassert>
  4. using namespace std;
  5.  
  6. ifstream fin ("euler.in");
  7. ofstream fout("euler.out");
  8.  
  9. int n , a[205][205], d[205], x[50000], y[50000], p , q;
  10.  
  11.  
  12. int main()
  13. {
  14. int i , j;
  15. fin >> n;
  16. while(fin >> i >> j)
  17. {
  18. a[i][j] = a[j][i] = 1;
  19. d[i] ++, d[j] ++;
  20. }
  21. p = 1; x[1] = 1;
  22. while(1)
  23. {
  24. int xpoz = 0;
  25. for(int i = 1 ; i <= p && xpoz == 0 ; ++i)
  26. if(d[x[i]] > 0)
  27. xpoz = i;
  28. if(xpoz == 0)break;
  29. q = 1; y[1] = x[xpoz];
  30. do{
  31. int ypoz = 0;
  32. for(int i =1 ; i <= n && ypoz == 0 ; i ++)
  33. if(a[y[q]][i] != 0)
  34. ypoz = i;
  35. d[y[q]] --;
  36. d[ypoz] --;
  37. a[y[q]][ypoz] = a[ypoz][y[q]] = 0;
  38. y[ ++ q] = ypoz;
  39. }while(y[q] != y[1]);
  40. for(int i = p; i > xpoz ; i --)
  41. x[i + q - 1] = x[i];
  42. for(int i = xpoz, j = 1 ; j <= q ; i ++, j ++)
  43. x[i] = y[j];
  44. p += q - 1;
  45. }
  46. fout << p << "\n";
  47. for(int i =1 ; i <= p ; i ++)
  48. fout << x[i] << " ";
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement