fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define task "disconnect"
  4. #define ALL(v) (v).begin(), (v).end()
  5. #define rep(i, l, r) for (int i = (l); i <= (r); ++i)
  6. #define Rep(i, r, l) for (int i = (r); i >= (l); --i)
  7. #define DB(X) { cerr << #X << " = " << (X) << '\n'; }
  8. #define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
  9. #define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
  10. #define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
  11. #define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
  12. #define SZ(x) ((int)(x).size())
  13. #define pb push_back
  14. #define eb emplace_back
  15. #define pf push_front
  16. #define F first
  17. #define S second
  18. #define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
  19. #define next ___next
  20. #define prev ___prev
  21. #define y1 ___y1
  22. #define left ___left
  23. #define right ___right
  24. #define y0 ___y0
  25. #define div ___div
  26. #define j0 ___j0
  27. #define jn ___jn
  28.  
  29. using ll = long long;
  30. using ld = long double;
  31. using ull = unsigned long long;
  32. using namespace std;
  33. typedef pair<int, int> ii;
  34. typedef pair<ii, int> iii;
  35. typedef vector<int> vi;
  36. typedef vector<ii> vii;
  37. typedef vector<ll> vl;
  38. const int N = 1e5 + 3;
  39. int n, m, st[N], ed[N], bit[N], neu, dep[N], pa[17][N];
  40. vi g[N];
  41. void upd(int p, int v)
  42. {
  43. for (; p <= n; p += p & (-p)) bit[p] += v;
  44. }
  45. int query(int p)
  46. {
  47. int res = 0;
  48. for (; p; p -= p & (-p)) res += bit[p];
  49. return res;
  50. }
  51. void dfs(int u, int p)
  52. {
  53. st[u] = ++neu;
  54. dep[u] = dep[p] + 1;
  55. pa[0][u] = p;
  56. rep(k, 1, 16) pa[k][u] = pa[k - 1][pa[k - 1][u]];
  57. for (int v : g[u]) if (v != p)
  58. dfs(v, u);
  59. ed[u] = neu;
  60. }
  61. int lca(int x, int y)
  62. {
  63. if (dep[x] < dep[y]) swap(x, y);
  64. Rep(k, 16, 0) if (dep[pa[k][x]] >= dep[y]) x = pa[k][x];
  65. if (x == y) return x;
  66. Rep(k, 16, 0) if (pa[k][x] != pa[k][y]) x = pa[k][x], y = pa[k][y];
  67. return pa[0][x];
  68. }
  69. int main()
  70. {
  71. ios_base::sync_with_stdio(0);
  72. cin.tie(0);
  73. freopen("disconnect.in", "r", stdin);
  74. freopen("disconnect.out", "w", stdout);
  75. cin >> n >> m;
  76. rep(i, 2, n)
  77. {
  78. int u, v;
  79. cin >> u >> v;
  80. g[u].eb(v);
  81. g[v].eb(u);
  82. }
  83. dfs(1, 0);
  84. //PR(eul, 1, neu);
  85. int vv = 0;
  86. while (m--)
  87. {
  88. int t, x, y, u, v;
  89. cin >> t >> x >> y;
  90. u = x ^ vv;
  91. v = y ^ vv;
  92. int z = lca(u, v);
  93. if (t == 1)
  94. {
  95. if (pa[0][v] == u) swap(u, v);
  96. upd(st[u], 1);
  97. upd(ed[u] + 1, -1);
  98. } else
  99. {
  100. int du = query(st[u]);
  101. int dv = query(st[v]);
  102. int dz = query(st[z]);
  103. if (du + dv - 2 * dz > 0)
  104. {
  105. cout << "NO\n";
  106. vv = v;
  107. } else
  108. {
  109. cout << "YES\n";
  110. vv = u;
  111. }
  112. }
  113. }
  114. return 0;
  115. }
  116.  
Success #stdin #stdout 0s 6260KB
stdin
Standard input is empty
stdout
Standard output is empty