func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int K = 18;   long long a[N], tree[N << 2], lazy[N << 2];   vector<int> v[N];   int anc[N][K], h[N], sz[N];   int c[N], pos[N];   int ct;   void build(int node, int st, int end) {     if (st == end) {       tree[node] = c[st];       return;     }     long long mid = st + end >> 1LL;     build(node << 1, st, mid);     build((node << 1) + 1, mid + 1, end);     tree[node] = tree[node << 1] + tree[(node << 1) + 1];   }   void update(int node, int st, int end, int l, int r, long long val) {     if (lazy[node]) {       tree[node] += (end - st + 1) * lazy[node];       if (st != end) {         lazy[node << 1] += lazy[node];         lazy[(node << 1) + 1] += lazy[node];       }       lazy[node] = 0;     }     if (st > end || r < st || end < l) return;     if (l <= st && end <= r) {       tree[node] += (end - st + 1) * val;       if (st != end) {         lazy[node << 1] += val;         lazy[(node << 1) + 1] += val;       }       return;     }     long long mid = st + end >> 1LL;     update(node << 1, st, mid, l, r, val);     update((node << 1) + 1, mid + 1, end, l, r, val);     tree[node] = tree[node << 1] + tree[(node << 1) + 1];   }   long long query(int node, int st, int end, int l, int r) {     if (st > end || r < st || end < l) return 0;     if (lazy[node]) {       tree[node] += (end - st + 1) * lazy[node];       if (st != end) {         lazy[node << 1] += lazy[node];         lazy[(node << 1) + 1] += lazy[node];       }       lazy[node] = 0;     }     if (l <= st && end <= r) return tree[node];     long long mid = st + end >> 1LL;     return (query(node << 1, st, mid, l, r) +             query((node << 1) + 1, mid + 1, end, l, r));   }   void dfs(int s, int P) {     c[ct + 1] = a[s];     pos[s] = ++ct;     anc[s][0] = P;     h[s] = h[P] + 1;     sz[s]++;     for (int i = 1; i < K; i++) anc[s][i] = anc[anc[s][i - 1]][i - 1];     for (auto i : v[s])       if (i != P) dfs(i, s), sz[s] += sz[i];   }   int LCA(int x, int y) {     int d = h[y] - h[x];     if (d < 0) swap(x, y);     d = abs(d);     for (int i = K - 1; i >= 0; i--)       if ((1 << i) & d) y = anc[y][i];     if (x == y) return x;     for (int i = K - 1; i >= 0; i--)       if (anc[x][i] != anc[y][i]) x = anc[x][i], y = anc[y][i];     return anc[x][0];   }   int lift(int x, int d) {     for (int i = K - 1; i >= 0; i--)       if ((1 << i) & d) x = anc[x][i];     return x;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     build(1, 1, n);     int t, val, l, r, x, ro = 1, yo, vo, go;     long long ho;     for (int i = 0; i < q; i++) {       cin >> t;       if (t == 1)         cin >> ro;       else if (t == 2) {         cin >> l >> r >> x;         yo = LCA(l, r), vo = LCA(l, ro), go = LCA(r, ro);         if (h[yo] < h[vo]) yo = vo;         if (h[yo] < h[go]) yo = go;         if (yo == ro) {           update(1, 1, n, 1, n, x);         } else if (LCA(yo, ro) == yo) {           update(1, 1, n, 1, n, x);           yo = lift(ro, h[ro] - h[yo] - 1);           update(1, 1, n, pos[yo], pos[yo] + sz[yo] - 1, -x);         } else {           update(1, 1, n, pos[yo], pos[yo] + sz[yo] - 1, x);         }       } else {         cin >> l;         if (l == ro) {           cout << query(1, 1, n, 1, n) <<   n ;         } else if (LCA(ro, l) == l) {           ho = query(1, 1, n, 1, n);           yo = lift(ro, h[ro] - h[l] - 1);           cout << ho - query(1, 1, n, pos[yo], pos[yo] + sz[yo] - 1) <<   n ;         } else {           cout << query(1, 1, n, pos[l], pos[l] + sz[l] - 1) <<   n ;         }       }     }     return 0;   }   