fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long MaxN = 1e5 + 5;
  5.  
  6. long long n;
  7. vector<long long> a[MaxN];
  8.  
  9. void input()
  10. {
  11. cin >> n;
  12.  
  13. for (long long i = 1; i <= n - 1; i++)
  14. {
  15. long long u, v;
  16. cin >> u >> v;
  17.  
  18. a[u].push_back(v);
  19. a[v].push_back(u);
  20. }
  21. }
  22.  
  23. void solve()
  24. {
  25. if (n <= 2)
  26. {
  27. cout << 1;
  28. return;
  29. }
  30.  
  31. long long cnt = 0;
  32.  
  33. for (long long i = 1; i <= n; i++)
  34. {
  35. if (a[i].size() == 1)
  36. {
  37. cnt++;
  38. }
  39. }
  40.  
  41. cout << cnt;
  42. }
  43.  
  44. int main()
  45. {
  46. input();
  47. solve();
  48. }
Success #stdin #stdout 0.01s 5924KB
stdin
Standard input is empty
stdout
1