fork download
  1.  
  2. #pragma GCC optimize("O3,unroll-loops")
  3. #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. #define files \
  9.   freopen("input.txt", "r", stdin); \
  10.   freopen("output.txt", "w", stdout);
  11.  
  12. #define rall(x) x.rbegin(), x.rend()
  13. #define all(x) x.begin(), x.end()
  14. #define sz(x) (int)x.size()
  15. #define ll long long
  16.  
  17. #define rep(ii, beg, till, inc) for (int ii = beg; ii < till; ii += inc)
  18. #define repr(ii, beg, till, inc) for (int ii = beg - 1; ii >= till; ii -= inc)
  19.  
  20. const ll MOD = 1e9 + 7;
  21. const int MXN = 2e5 + 5;
  22.  
  23. int dx[] = {1, -1, 0, 0};
  24. int dy[] = {0, 0, 1, -1};
  25.  
  26. int edges = 0;
  27. vector<int> graph[MXN];
  28. int dfs(int node, int par)
  29. {
  30. int one = 0;
  31. for (int child : graph[node])
  32. {
  33. if (child == par)
  34. continue;
  35. int cur = dfs(child, node);
  36. edges += cur == 2;
  37. one += cur == 1;
  38. }
  39. one = one != 0;
  40. ++one;
  41. edges += one == 2;
  42. one %= 2;
  43. return one;
  44. }
  45. void sol(int tc)
  46. {
  47. int node;
  48. cin >> node;
  49. rep(ii, 1, node, 1)
  50. {
  51. int u, v;
  52. cin >> u >> v;
  53. graph[u].push_back(v);
  54. swap(u, v);
  55. graph[u].push_back(v);
  56. }
  57. dfs(1, 1);
  58. cout << edges << "\n";
  59. }
  60.  
  61. int main()
  62. {
  63. ios::sync_with_stdio(false);
  64. cin.tie(nullptr);
  65.  
  66. int T = 1;
  67. // cin >> T;
  68. for (int ii = 1; ii <= T; ++ii)
  69. sol(ii);
  70. }
  71.  
Runtime error #stdin #stdout 0.01s 8012KB
stdin
Standard input is empty
stdout
Standard output is empty