Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 30010;
  4. int n, arb, temp = 1, viz[N];
  5. vector<int> v[N];
  6. void dfs(int);
  7. int main()
  8. {
  9. cin >> n;
  10. for(int x, y, i = 1; i <= n; i++)
  11. {
  12. cin >> x >> y;
  13. v[x].push_back(y);
  14. v[y].push_back(x);
  15. }
  16. for(int i = 1; i <= n; i++)
  17. sort(v[i].begin(), v[i].end());
  18. dfs(1);
  19. cout << endl << arb;
  20. return 0;
  21. }
  22. void dfs(int nod)
  23. {
  24. cout << temp << ' ';
  25. viz[nod] = 1;
  26. vector <int> tempv;
  27. for(auto it: v[nod])
  28. {
  29. if(!viz[it])
  30. {
  31. tempv.push_back(it);
  32. viz[it] = 1;
  33. temp++;
  34. if(temp == n)
  35. arb++;
  36. }
  37. }
  38. for(auto vec: tempv)
  39. dfs(vec);
  40. for(auto vec: tempv)
  41. viz[vec] = 0;
  42. temp -= tempv.size();
  43. viz[nod] = 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement