fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define int ll
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "gen"
  33.  
  34. const int MOD = 1e9 + 7;
  35. const int inf = 1e9 + 27092008;
  36. const ll INF = 1e18 + 27092008;
  37. const int N = 2e5 + 5;
  38. int n, m, q;
  39. int a[N];
  40. int tin[N], tout[N], h[N], timer = 0, P[N][20];
  41. vector<int> G[N];
  42.  
  43. void dfs(int u, int par) {
  44. tin[u] = ++timer;
  45. for(int v : G[u]) if (v != par) {
  46. P[v][0] = u;
  47. h[v] = h[u] + 1;
  48. dfs(v, u);
  49. }
  50. tout[u] = timer;
  51. }
  52.  
  53. int LCA(int u, int v) {
  54. if (h[u] < h[v]) swap(u, v);
  55. int s = h[u] - h[v];
  56. RED(j, 20) if (BIT(s, j))
  57. u = P[u][j];
  58. if (u == v) return u;
  59. RED(j, 20) if (P[u][j] != P[v][j]) {
  60. u = P[u][j];
  61. v = P[v][j];
  62. }
  63. return P[u][0];
  64. }
  65.  
  66. int dist(int u, int v) {
  67. int p = LCA(u, v);
  68. return h[u] + h[v] - 2 * h[p];
  69. }
  70.  
  71. void init(void) {
  72. cin >> n >> m >> q;
  73. FOR(i, 1, m) cin >> a[i];
  74. FOR(i, 2, n) {
  75. int u, v;
  76. cin >> u >> v;
  77. G[u].pb(v);
  78. G[v].pb(u);
  79. }
  80. }
  81.  
  82. void process(void) {
  83. dfs(1, -1);
  84. FOR(j, 1, 19) FOR(i, 1, n)
  85. P[i][j] = P[P[i][j - 1]][j - 1];
  86. vector<ll> ans(m + 5, 0);
  87. while(q--) {
  88. int t; cin >> t;
  89. if (t == 1) {
  90. int u, v; cin >> u >> v;
  91. FOR(i, 1, m) if (a[i] == u)
  92. ans[i] += v;
  93. } else if (t == 2){
  94. int l, r, z;
  95. cin >> l >> r >> z;
  96. FOR(i, l, r) {
  97. ans[i] -= dist(z, a[i]);
  98. a[i] = z;
  99. }
  100. } else {
  101. int u; cin >> u;
  102. cout << ans[u] << '\n';
  103. }
  104. }
  105. }
  106.  
  107. signed main() {
  108. ios_base::sync_with_stdio(0);
  109. cin.tie(0); cout.tie(0);
  110. if (fopen(task".inp", "r")) {
  111. freopen(task".inp", "r", stdin);
  112. freopen(task".ans", "w", stdout);
  113. }
  114. int tc = 1;
  115. // cin >> tc;
  116. while(tc--) {
  117. init();
  118. process();
  119. }
  120. return 0;
  121. }
  122.  
Success #stdin #stdout 0.01s 13876KB
stdin
Standard input is empty
stdout
Standard output is empty