description: Chanek Jones is back, helping his long-lost relative Indiana Jones, to find a secret treasure in a maze buried below a desert full of illusions.
  
  The map of the labyrinth forms a tree with n rooms numbered from 1 to n and n - 1 tunnels connecting them such that it is possible to travel between each pair of rooms through several tunnels.
  
  The i-th room (1 ≤ i ≤ n) has a_i illusion rate. To go from the x-th room to the y-th room, there must exist a tunnel between x and y, and it takes max(|a_x + a_y|, |a_x - a_y|) energy. |z| denotes the absolute value of z.
  
  To prevent grave robbers, the maze can change the illusion rate of any room in it. Chanek and Indiana would ask q queries.
  
  There are two types of queries to be done:
  
    * 1\ u\ c — The illusion rate of the x-th room is changed to c (1 ≤ u ≤ n, 0 ≤ |c| ≤ 10^9). 
    * 2\ u\ v — Chanek and Indiana ask you the minimum sum of energy needed to take the secret treasure at room v if they are initially at room u (1 ≤ u, v ≤ n). 
  
  
  
  Help them, so you can get a portion of the treasure!
  
  Input
  
  The first line contains two integers n and q (2 ≤ n ≤ 10^5, 1 ≤ q ≤ 10^5) — the number of rooms in the maze and the number of queries.
  
  The second line contains n integers a_1, a_2, …, a_n (0 ≤ |a_i| ≤ 10^9) — inital illusion rate of each room.
  
  The i-th of the next n-1 lines contains two integers s_i and t_i (1 ≤ s_i, t_i ≤ n), meaning there is a tunnel connecting s_i-th room and t_i-th room. The given edges form a tree.
  
  The next q lines contain the query as described. The given queries are valid.
  
  Output
  
  For each type 2 query, output a line containing an integer — the minimum sum of energy needed for Chanek and Indiana to take the secret treasure.
  
  Example
  
  Input
  
  
  6 4
  10 -9 2 -1 4 -6
  1 5
  5 4
  5 6
  6 2
  6 3
  2 1 2
  1 1 -3
  2 1 2
  2 3 3
  
  
  Output
  
  
  39
  32
  0
  
  Note
  
  <image>
  
  In the first query, their movement from the 1-st to the 2-nd room is as follows.
  
    * 1 → 5 — takes max(|10 + 4|, |10 - 4|) = 14 energy. 
    * 5 → 6 — takes max(|4 + (-6)|, |4 - (-6)|) = 10 energy. 
    * 6 → 2 — takes max(|-6 + (-9)|, |-6 - (-9)|) = 15 energy. 
  
  In total, it takes 39 energy.
  
  In the second query, the illusion rate of the 1-st room changes from 10 to -3.
  
  In the third query, their movement from the 1-st to the 2-nd room is as follows.
  
    * 1 → 5 — takes max(|-3 + 4|, |-3 - 4|) = 7 energy. 
    * 5 → 6 — takes max(|4 + (-6)|, |4 - (-6)|) = 10 energy. 
    * 6 → 2 — takes max(|-6 + (-9)|, |-6 - (-9)|) = 15 energy. 
  
  
  
  Now, it takes 32 energy.
solution: #include <bits/stdc++.h>
  using namespace std;
  long double PI = acos(-1);
  long double DEL = 1e-12;
  long long M = 1e9 + 7;
  const long long N = 3e5 + 10;
  long long cnt, sum, mx, mn, ans, a[N], b[N];
  long long n, m, d, i, j, k, l, p, q, r, t, w, x, y, z, tc;
  string s;
  struct HEAVY_LIGHT {
    vector<long long> dfsarray, depth, heavy, par, sub, head, pos, seg;
    void buildseg(long long i, long long l, long long r) {
      if (l == r) {
        seg[i] = a[dfsarray[l]];
        return;
      }
      buildseg(2 * i, l, ((l + r) >> 1));
      buildseg(2 * i + 1, ((l + r) >> 1) + 1, r);
      seg[i] = seg[2 * i] + seg[2 * i + 1];
    }
    void upd(long long x, long long v, long long i = 1, long long l = 0,
             long long r = n - 1) {
      if (x < l or x > r) {
        return;
      }
      if (l == r) {
        seg[i] = v;
        return;
      }
      upd(x, v, 2 * i, l, ((l + r) >> 1));
      upd(x, v, 2 * i + 1, ((l + r) >> 1) + 1, r);
      seg[i] = seg[2 * i] + seg[2 * i + 1];
    }
    long long query(long long a, long long b, long long i = 1, long long l = 0,
                    long long r = n - 1) {
      if (l > b or r < a) {
        return 0;
      }
      if (a <= l and r <= b) {
        return seg[i];
      }
      return query(a, b, 2 * i, l, ((l + r) >> 1)) +
             query(a, b, 2 * i + 1, ((l + r) >> 1) + 1, r);
    }
    void build(vector<vector<long long>> &g, long long root) {
      long long sz = n;
      depth.resize(sz + 1);
      heavy.resize(sz + 1);
      par.resize(sz + 1);
      pos.resize(sz + 1);
      head.resize(sz + 1);
      sub.resize(sz + 1);
      seg.resize(4 * sz + 1);
      dfs(root, root, g);
      decompose(root, root, g);
      buildseg(1, 0, n - 1);
    }
    void dfs(long long i, long long p, vector<vector<long long>> &g) {
      depth[i] = depth[p] + 1;
      par[i] = p;
      sub[i] = 1;
      long long ms = 0, hc = -1;
      for (auto j : g[i]) {
        if (j == p) continue;
        dfs(j, i, g);
        sub[i] += sub[j];
        if (sub[j] > ms) {
          ms = sub[j];
          hc = j;
        }
      }
      heavy[i] = hc;
    }
    void decompose(long long i, long long h, vector<vector<long long>> &g) {
      pos[i] = dfsarray.size();
      dfsarray.push_back(i);
      head[i] = h;
      if (heavy[i] != -1) {
        decompose(heavy[i], h, g);
      }
      for (auto j : g[i]) {
        if (j == par[i] or j == heavy[i]) continue;
        decompose(j, j, g);
      }
    }
    long long lca(long long u, long long v) {
      for (; head[u] != head[v]; u = par[head[u]]) {
        if (depth[head[u]] < depth[head[v]]) {
          swap(u, v);
        }
      }
      return depth[u] > depth[v] ? v : u;
    }
    long long get(long long u, long long v) {
      long long ans = 0;
      long long sub = a[u] + a[v];
      for (; head[u] != head[v]; u = par[head[u]]) {
        if (depth[head[u]] < depth[head[v]]) {
          swap(u, v);
        }
        ans += query(pos[head[u]], pos[u]);
      }
      if (depth[u] > depth[v]) {
        swap(u, v);
      }
      ans += query(pos[u], pos[v]);
      ans *= 2;
      return ans - sub;
    }
  };
  vector<vector<long long>> g;
  int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
      a[i] = abs(a[i]);
    }
    g.resize(n + 1);
    for (long long i = 1; i < n; i++) {
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    HEAVY_LIGHT h;
    h.build(g, 1);
    while (q--) {
      cin >> t >> x >> y;
      if (t == 1) {
        h.upd(h.pos[x], abs(y));
        a[x] = abs(y);
      } else {
        cout << h.get(x, y);
        cout << "\n";
      }
    }
  }
  