fork download
  1. #include<bits/stdc++.h>
  2. #include<ext/pb_ds/assoc_container.hpp>
  3. #include<ext/pb_ds/tree_policy.hpp>
  4. #define ll long long int
  5. #define ld long double
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8. #define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  9. typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
  10. const ll N = 1e5 + 5, MOD1 = 998244353, MOD2 = 1e9 + 7;
  11.  
  12. void solve(ll t) {
  13. ll n, q;
  14. cin >> n;
  15. vector<vector<ll>> adj(n + 1);
  16. set<ll> s;
  17. for (int i = 1; i <= n; i++) s.insert(i);
  18. for (int i = 0; i < n - 1; i++) {
  19. ll a, b;
  20. cin >> a >> b;
  21. adj[a].push_back(b);
  22. adj[b].push_back(a);
  23. }
  24. cin >> q;
  25. while (q--) {
  26. string x;
  27. cin >> x;
  28. if (x == "Count") {
  29. cout << s.size() << "\n";
  30. } else {
  31. ll node;
  32. cin >> node;
  33. if (s.find(node) != s.end()) {
  34. s.erase(node);
  35. }
  36. for (auto it: adj[node]) {
  37. if (s.find(it) != s.end()) {
  38. s.erase(it);
  39. }
  40. }
  41. }
  42. }
  43. }
  44.  
  45. signed main() {
  46. FAST
  47. #ifndef ONLINE_JUDGE
  48. freopen("input.txt", "r", stdin);
  49. freopen("output.txt", "w", stdout);
  50. #endif
  51. int t = 1;
  52. // cin >> t;
  53. for (ll i = 1; i <= t; i++) {
  54. solve(i);
  55. if (i < t)
  56. cout << endl;
  57. }
  58. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty