Problem:
Do use segment tree

Given a tree with n (1 ≤ n ≤ 200,000) nodes and a list of q (1 ≤ q ≤ 100,000) queries,
process the queries in order and output a value for each output query.
The given tree is connected and each node on the tree has a weight wi (-10,000 ≤ wi ≤ 10,000).

Each query consists of a number ti (ti = 1, 2), which indicates the type of the query , and three numbers ai, bi and ci (1 ≤ ai, bi ≤ n, -10,000 ≤ ci ≤ 10,000).
Depending on the query type, process one of the followings:

(ti = 1: modification query)
Change the weights of all nodes on the shortest path between ai and bi (both inclusive) to ci.

(ti = 2: output query)
First, create a list of weights on the shortest path between ai and bi (both inclusive) in order. After that, output the maximum sum of a non-empty continuous subsequence of the weights on the list. ci is ignored for output queries.

Input

The first line contains two integers n and q.
On the second line, there are n integers which indicate w1, w2, ... , wn.

Each of the following n - 1 lines consists of two integers si and ei (1 ≤ si, ei ≤ n),
which means that there is an edge between si and ei.

Finally the following q lines give the list of queries, each of which contains four integers in the format described above.
Queries must be processed one by one from top to bottom.

Output

For each output query, output the maximum sum in one line.

Sample Input 1

3 4
1 2 3
1 2
2 3
2 1 3 0
1 2 2 -4
2 1 3 0
2 2 2 0

Output for the Sample Input 1

6
3
-4

Sample Input 2

7 5
-8 5 5 5 5 5 5
1 2
2 3
1 4
4 5
1 6
6 7
2 3 7 0
2 5 2 0
2 4 3 0
1 1 1 -1
2 3 7 0

Output for the Sample Input 2

12
10
10
19

Sample Input 3

21 30
10 0 -10 -8 5 -5 -4 -3 1 -2 8 -1 -7 2 7 6 -9 -6 3 4 9
10 3
3 2
3 12
12 4
4 13
4 9
10 21
21 1
1 11
11 14
1 15
10 6
6 17
6 16
6 5
5 18
5 19
10 7
10 8
8 20
1 1 21 -10
1 3 19 10
2 1 13 0
1 4 18 8
1 5 17 -5
2 16 7 0
1 6 16 5
1 7 15 4
2 4 20 0
1 8 14 3
1 9 13 -1
2 9 18 0
1 10 12 2
1 11 11 -8
2 21 15 0
1 12 10 1
1 13 9 7
2 6 14 0
1 14 8 -2
1 15 7 -7
2 10 2 0
1 16 6 -6
1 17 5 9
2 12 17 0
1 18 4 6
1 19 3 -3
2 11 8 0
1 20 2 -4
1 21 1 -9
2 5 19 0

Output for the Sample Input 3

20
9
29
27
10
12
1
18
-2
-3

Solution in C# (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
//using System.Numerics;

namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var m = sc.Integer();
            var G = new HeavyLightDecomposition(n);
            var A = sc.Integer(n);
            for (int i = 0; i < n - 1; i++)
            {
                var a = sc.Integer() - 1;
                var b = sc.Integer() - 1;
                G.AddEdge(a, b);
            }
            G.ComputeSubTreeSize(0);
            G.Decomposite(new Edge(-1, 0), -1, 0, 0);
            G.BuildLCA();
            G.BuildHLLCA();
            for (int i = 0; i < n; i++)
            {
                G.Update(i, i, A[i]);
            }
            for (int i = 0; i < m; i++)
            {
                var t = sc.Integer();
                var a = sc.Integer() - 1;
                var b = sc.Integer() - 1;
                var c = sc.Integer();
                var lca = G.GetLCA(a, b);
                if (t == 1)
                {
                    //Debug.WriteLine("{0}->{1} {2}", a, b, c);
                    G.Update(lca, a, c);
                    G.Update(lca, b, c);
                }
                else
                {
                    var l = G.Query(lca, a);
                    var r = G.Query(lca, b);
                    var max = Math.Max(l.Value, r.Value);
                    if (lca != a && lca != b)
                        max = Math.Max(max, l.Key + r.Key - G.Query(lca, lca).Key);
                    IO.Printer.Out.WriteLine(max);
                }
            }
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer : StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie.Select(x => x.ToString()).ToArray()); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion

#region HLDecomposition
public struct Edge
{
    public int from, to;
    public Edge(int f, int t)
    {
        from = f; to = t;
    }
    public override string ToString()
    {
        return string.Format("{0}->{1}", from, to);
    }
}
public class HeavyLightDecomposition
{
    public void Update(int from, int to, int val)
    {
        var f = go[from];
        var t = go[to];
        if (f.id == t.id)
        {
            f.seg.Update(pos[from], pos[to] + 1, val);
        }
        else
        {
            var ch = GetAncestorAt(t, f.depth + 1);
            var med = H[ch];
            f.seg.Update(pos[from], pos[med.light.from] + 1, val);
            Update(med.light.to, to, val);
        }

    }
    public KeyValuePair<long, long> Query(int from, int to)
    {
        var f = go[from];
        var t = go[to];
        if (f.id == t.id)
        {
            var l = f.seg.QueryLeft(pos[from], pos[to] + 1);
            var max = f.seg.Query(pos[from], pos[to] + 1);
            return new KeyValuePair<long, long>(l, max);
        }
        else
        {
            var ch = GetAncestorAt(t, f.depth + 1);
            var med = H[ch];
            var l = f.seg.QueryLeft(pos[from], pos[med.light.from] + 1);
            var lsum = f.seg.QuerySum(pos[from], pos[med.light.from] + 1);
            var r = Query(med.light.to, to);
            var lmax = Math.Max(l, lsum + r.Key);
            var max = Math.Max(lmax, r.Value);
            max = Math.Max(max, f.seg.QueryRight(pos[from], pos[med.light.from] + 1) + r.Key);
            max = Math.Max(max, f.seg.Query(pos[from], pos[med.light.from] + 1));
            return new KeyValuePair<long, long>(lmax, max);
        }
    }

    List<Edge>[] G;
    List<Node> H = new List<Node>();
    int[] subTreeSize;
    int[] par;
    int[] pos;
    int[,] parent;
    int[] depth;

    Node[] go;
    int[,] hlpar;
    public HeavyLightDecomposition(int n)
    {
        G = Enumerate(n, x => new List<Edge>());
        subTreeSize = new int[n];
        pos = new int[n];
        depth = new int[n];
        par = new int[n];
        parent = new int[32, n];
        go = new Node[n];
    }
    public void AddEdge(int f, int t)
    {
        G[f].Add(new Edge(f, t));
        G[t].Add(new Edge(t, f));
    }
    public void ComputeSubTreeSize(int root)
    {
        var stack = new Stack<KeyValuePair<int, int>>();
        stack.Push(new KeyValuePair<int, int>(root, -1));
        var visit = new bool[G.Length];
        while (stack.Any())
        {
            var p = stack.Pop();
            var cur = p.Key;
            var prev = p.Value;
            if (visit[p.Key])
            {
                foreach (var next in G[cur])
                {
                    var to = To(next);
                    if (to != prev)
                        subTreeSize[cur] += subTreeSize[to];
                }
            }
            else
            {
                visit[cur] = true;
                stack.Push(new KeyValuePair<int, int>(cur, prev));
                subTreeSize[cur]++;
                foreach (var next in G[cur])
                {
                    var to = To(next);
                    if (to != prev) stack.Push(new KeyValuePair<int, int>(to, cur));
                }
            }
        }
    }
    public void Decomposite(Edge light, int prevId, int d, int lv)
    {
        var node = new Node();
        node.light = light;
        node.id = H.Count;
        node.par = prevId;
        node.depth = lv;
        H.Add(node);
        var prev = light.from;
        var cur = light.to;
        while (cur != prev)
        {
            var next = cur;
            var max = 0;
            depth[cur] = d;
            par[cur] = prev;
            go[cur] = node;
            pos[cur] = node.heavy.Count;
            foreach (var to in G[cur])
            {
                var t = To(to);
                if (t != prev) max = Math.Max(max, subTreeSize[t]);
            }
            foreach (var to in G[cur])
            {
                var t = To(to);
                if (t == prev) continue;
                if (max == subTreeSize[t])
                {
                    //Debug.WriteLine("{0}->{1}", cur, t);
                    max = 1 << 30;
                    next = t;
                    node.heavy.Add(to);
                }
                else Decomposite(to, node.id, d + 1, lv + 1);
            }
            prev = cur;
            cur = next;
            d++;
        }
        node.init();

    }
    public void BuildLCA()
    {
        for (int k = 0; k < 31; k++)
            for (int v = 0; v < G.Length; v++)
                parent[k, v] = -1;
        for (int i = 0; i < G.Length; i++)
            parent[0, i] = par[i];
        for (int k = 0; k < 31; k++)
        {
            for (int v = 0; v < G.Length; v++)
                if (parent[k, v] < 0) parent[k + 1, v] = -1;
                else parent[k + 1, v] = parent[k, parent[k, v]];
        }

    }
    public void BuildHLLCA()
    {
        hlpar = new int[32, H.Count];
        for (int k = 0; k < 31; k++)
            for (int v = 0; v < H.Count; v++)
                hlpar[k, v] = -1;
        for (int i = 0; i < H.Count; i++)
            hlpar[0, i] = H[i].par;
        for (int k = 0; k < 31; k++)
        {
            for (int v = 0; v < H.Count; v++)
                if (hlpar[k, v] < 0) hlpar[k + 1, v] = -1;
                else hlpar[k + 1, v] = hlpar[k, hlpar[k, v]];
        }

    }
    public int GetAncestorAt(Node v, int d)
    {
        if (v.depth < d)
            throw new Exception();
        for (int i = 0; i < 32; i++)
            if ((((v.depth - d) >> i) & 1) == 1)
                v = H[hlpar[i, v.id]];
        return v.id;
    }


    public int To(Edge t) { return t.to; }


    public int GetLCA(int u, int v)
    {
        if (depth[u] > depth[v]) { var tmp = u; u = v; v = tmp; }
        for (int k = 0; k < 32; k++)
            if ((((depth[v] - depth[u]) >> k) & 1) == 1)
                v = parent[k, v];
        if (u == v)
            return u;
        for (int i = 31; i >= 0; i--)
            if (parent[i, u] != parent[i, v])
            {
                u = parent[i, u];
                v = parent[i, v];
            }
        return parent[0, u];
    }
    public int GetAncestor(int v, int k)
    {
        var to = depth[v] - k;
        for (int i = 0; i < 32; i++)
            if ((((depth[v] - to) >> i) & 1) == 1)
                v = parent[i, v];
        return v;
    }
    public int GetAncestorAt(int v, int d)
    {
        if (depth[v] < d)
            throw new Exception();
        for (int i = 0; i < 32; i++)
            if ((((depth[v] - d) >> i) & 1) == 1)
                v = parent[i, v];
        return v;
    }
    static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }

}
#endregion
public class Node
{
    public Edge light;
    public List<Edge> heavy = new List<Edge>();
    public int par;
    public int depth;
    public int id;
    public LazyEvaluateRangeAddSegmentTree seg;
    public void init()
    {
        seg = new LazyEvaluateRangeAddSegmentTree(heavy.Count + 1);
    }
    public override string ToString()
    {
        var s = new List<int>();
        s.Add(light.from);
        s.Add(light.to);
        foreach (var e in heavy)
            s.Add(e.to);
        return s.AsJoinedString("->");
    }
}

#region LazyEvaluateRangeAddSegmentTree
public class LazyEvaluateRangeAddSegmentTree
{
    int n;
    long[] sum;
    long[] left, right, ans;
    long[] lazy;
    public LazyEvaluateRangeAddSegmentTree(int size)
    {
        n = 1;
        while (n < size)
            n <<= 1;
        sum = new long[n << 1];
        lazy = new long[n << 1];
        for (int i = 0; i < lazy.Length; i++)
            lazy[i] = int.MinValue;
        left = new long[n << 1];
        right = new long[n << 1];
        ans = new long[n << 1];
    }
    private void lazyEval(int k, int a, int b)
    {
        if (lazy[k] == int.MinValue)
            return;
        Update(a, (a + b) >> 1, lazy[k], k << 1, a, (a + b) >> 1);
        Update((a + b) >> 1, b, lazy[k], (k << 1) + 1, (a + b) >> 1, b);
        lazy[k] = int.MinValue;
    }
    private void eval(int k)
    {
        int l = k << 1, r = (k << 1) + 1;
        ans[k] = Math.Max(Math.Max(ans[l], ans[r]), left[r] + right[l]);
        sum[k] = sum[l] + sum[r];
        left[k] = Math.Max(sum[l] + left[r], left[l]);
        right[k] = Math.Max(sum[r] + right[l], right[r]);
    }
    public void Update(int a, int b, int v)
    {
        Update(a, b, v, 1, 0, n);
    }
    private void Update(int a, int b, long v, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return;
        else if (a <= l && r <= b)
        {
            lazy[k] = v;
            sum[k] = lazy[k] * (r - l);
            left[k] = right[k] = ans[k] = lazy[k] >= 0 ? (r - l) * lazy[k] : lazy[k];
        }
        else
        {
            lazyEval(k, l, r);
            Update(a, b, v, k << 1, l, (l + r) >> 1);
            Update(a, b, v, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
        }
    }
    public long Query(int a, int b) { return Query(a, b, 1, 0, n); }
    private long Query(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return int.MinValue;
        if (a <= l && r <= b)
            return ans[k];
        else
        {
            lazyEval(k, l, r);
            var vl = Query(a, b, k << 1, l, (l + r) >> 1);
            var vr = Query(a, b, (k << 1) + 1, (l + r) >> 1, r);
            var vll = QueryRight(a, b, k << 1, l, (l + r) >> 1);
            var vrr = QueryLeft(a, b, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
            return Math.Max(Math.Max(vl, vr), vll + vrr);
        }
    }
    public long QuerySum(int a, int b) { return QuerySum(a, b, 1, 0, n); }
    private long QuerySum(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return 0;
        if (a <= l && r <= b)
            return sum[k];
        else
        {
            lazyEval(k, l, r);
            var vl = QuerySum(a, b, k << 1, l, (l + r) >> 1);
            var vr = QuerySum(a, b, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
            return vl + vr;
        }
    }
    public long QueryLeft(int a, int b) { return QueryLeft(a, b, 1, 0, n); }
    private long QueryLeft(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return int.MinValue;
        if (a <= l && r <= b)
            return left[k];
        else
        {
            lazyEval(k, l, r);
            var vl = QueryLeft(a, b, k << 1, l, (l + r) >> 1);
            var lsum = QuerySum(a, b, k << 1, l, (l + r) >> 1);
            var vr = QueryLeft(a, b, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
            return Math.Max(vl, lsum + vr);
        }
    }
    public long QueryRight(int a, int b) { return QueryRight(a, b, 1, 0, n); }
    private long QueryRight(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return int.MinValue;
        if (a <= l && r <= b)
            return right[k];
        else
        {
            lazyEval(k, l, r);
            var vl = QueryRight(a, b, k << 1, l, (l + r) >> 1);
            var vr = QueryRight(a, b, (k << 1) + 1, (l + r) >> 1, r);
            var rsum = QuerySum(a, b, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
            return Math.Max(vl + rsum, vr);
        }
    }
}
#endregion