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++11 (judge verdict: Time Limit Exceeded)

#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <climits>
#include <cctype>
#include <cstdio>
#include <unistd.h>
#include <cassert>
#include <cstring>

using namespace std;
typedef long long ll;
#define int ll
int n,q;
int w[222222];
vector<int> g[222222];
vector<int> ch[222222];
vector<int> G[222222];
int tdepth[222222];
int f[222222];
int par[222222];
int ix[222222];
int chi[222222];
int sz[222222];
int depth[222222];
int dpar[222222];
int kk;
const pair<int,int> F(-114514810,-114514810);

void dfs(int v,int pre)
{
  queue<pair<int,int> > q;
  queue<int> lf;
  q.push(make_pair(v,pre));
  par[v] = -1;
  tdepth[v] = 0;
  for( int i = 0; i < n; i++ ) sz[i] = 1;
  while( !q.empty() ) {
    pair<int,int> p = q.front(); q.pop();
    bool o = false;
    for( int i = 0; i < int(g[p.first].size()); i++ ) {
      if( p.second != g[p.first][i] ) {
        par[g[p.first][i]] = p.first;
        tdepth[g[p.first][i]] = tdepth[p.first]+1;
        ch[p.first].push_back(g[p.first][i]);
        q.push(make_pair(g[p.first][i],p.first));
        o = true;
      }
    }
    if( !o ) {
      lf.push(p.first);
    }
  }
  while( !lf.empty() ) {
    int p = lf.front(); lf.pop();
    if( par[p] >= 0 ) {
      sz[par[p]] += sz[p];
      lf.push(par[p]);
    }
  }
}

void dec(int v,int d)
{
  queue<tuple<int,int,int> >q;
  q.push(make_tuple(v,d,kk));
  while( !q.empty() ) {
    v = get<0>(q.front());
    d = get<1>(q.front());
    int K = get<2>(q.front()); q.pop();
    ix[v] = G[K].size();
    G[K].push_back(v);
    f[v] = K;
    depth[K] = d;
    int idx = -1;
    for( int i = 0; i < int(ch[v].size()); i++ ) {
      if( idx == -1 || sz[ch[v][i]] >= sz[idx] ) {
        idx = ch[v][i];
      }
    }
    if( idx >= 0 ) {
      q.push(make_tuple(idx,d,K));
    }
    for( int i = 0; i < int(ch[v].size()); i++ ) {
      if( ch[v][i] != idx ) {
        kk += 1;
        chi[kk] = ch[v][i];
        dpar[kk] = f[v];
        q.push(make_tuple(ch[v][i],d+1,kk));
      }
    }
  }
}

struct segtree {
  int n;
  struct dat {
    int ans,all,left,right;
    dat(){}
    dat(const dat& l,const dat& r) {
      ans = max(max(l.ans,r.ans),l.right+r.left);
      all = l.all+r.all;
      left = max(l.left,l.all+r.left);
      right = max(r.right,r.all+l.right);
    }
    explicit dat(int a) {
      ans = all = left = right = a;
    }
  };
  vector<dat> d;
  vector<pair<int,int> > lazy;
  segtree(){}
  void init(vector<int>& g) {
    n = 1;
    while( n < int(g.size()) ) n *= 2;
    d.resize(n*2-1);
    lazy.resize(n*2-1,F);
    for( int i = 0; i < int(g.size()); i++ ) {
      d[i+(n-1)] = dat(w[g[i]]);
    }
    for( int i = n-2; i >= 0; i-- ) {
      d[i] = dat(d[i*2+1],d[i*2+2]);
    }
  }
  void push(int k) {
    if( lazy[k] != F ) {
      d[k].all = lazy[k].first;
      if( lazy[k].first >= 0 ) {
        d[k].left = lazy[k].first;
        d[k].right = lazy[k].first;
        d[k].ans = d[k].all;
      } else {
        d[k].left = lazy[k].second;
        d[k].right = lazy[k].second;
        d[k].ans = lazy[k].second;
      }
      if( k*2+2 < int(d.size()) ) {
        lazy[k].first >>= 1;
        lazy[k*2+1] = lazy[k*2+2] = lazy[k];
      }
      lazy[k] = F;
    }
  }
  inline void update(int i,int j,int l,int r,int k,int v) {
    push(k);
    if( j <= l || r <= i ) return;
    if( l <= i && j <= r ) {
      lazy[k] = make_pair(v,v/(j-i));
      push(k);
    } else {
      update(i,(i+j)>>1,l,r,(k<<1)+1,v>>1);
      update((i+j)>>1,j,l,r,(k<<1)+2,v>>1);
      d[k] = dat(d[(k<<1)+1],d[(k<<1)+2]);
    }
  }
  inline void update(int l,int r,int v) {
    update(0,n,l,r,0,v*n);
  }
  inline dat get(int i,int j,int l,int r,int k) {
    //printf("%d %d %d %d %d\n",i,j,l,r,k);
    push(k);
    static const int inf = 1000000011;
    if( j <= l || r <= i ) return std::move(dat(-inf));
    if( l <= i && j <= r ) {
      return d[k];
    } else {
      dat ld = std::move(get(i,(i+j)>>1,l,r,(k<<1)+1));
      dat rd = std::move(get((i+j)>>1,j,l,r,(k<<1)+2));
      if( ld.all == -inf ) return std::move(rd);
      if( rd.all == -inf ) return std::move(ld);
      return std::move(dat(ld,rd));
    }
  }
  inline dat get(int l,int r) {
    return get(0,n,l,r,0);
  }
  void print() {
    int c = 1,w=n,cnt=0;
    for( int i = 0; i < 2*n-1; i++ ) {
      push(i);
      cnt += 1;
      printf("(ans:%d,l:%d,r:%d,a:%d) ",d[i].ans,d[i].left,d[i].right,d[i].all);
      if( c == cnt ) {
        puts("");
        c *= 2;
        cnt = 0;
        w /= 2;
      }
    }
    puts("");
  }
};

segtree t[222222];

const int inf = 1145141919;
segtree::dat DF(-inf);
inline segtree::dat merge(segtree::dat a,segtree::dat b)
{
  if( a.all == -inf ) return b;
  if( b.all == -inf ) return a;
  return segtree::dat(a,b);
}

inline void update(int a,int b,int c)
{
  int aa = f[a];
  int bb = f[b];
  while( depth[aa] > depth[bb] ) {
    t[aa].update(0,ix[a]+1,c);
    a = par[G[aa][0]];
    aa = dpar[aa];
  }
  while( depth[bb] > depth[aa] ) {
    t[bb].update(0,ix[b]+1,c);
    b = par[G[bb][0]];
    bb = dpar[bb];
  }
  while( aa != bb ) {
    t[aa].update(0,ix[a]+1,c);
    t[bb].update(0,ix[b]+1,c);
    a = par[G[aa][0]];
    b = par[G[bb][0]];
    aa = dpar[aa];
    bb = dpar[bb];
  }
  t[aa].update(min(ix[a],ix[b]),max(ix[a],ix[b])+1,c);
}

segtree::dat mid;
segtree::dat dat[514],rev_dat[514];
segtree::dat trev_dat[514];
int dat_size,rev_dat_size;

inline int get(int a,int b)
{
  int aa = f[a];
  int bb = f[b];
  dat_size = rev_dat_size = 0;
  while( depth[aa] > depth[bb] ) {
    dat[dat_size++] = std::move(t[aa].get(0,ix[a]+1));
    a = par[G[aa][0]];
    aa = dpar[aa];
  }
  while( depth[bb] > depth[aa] ) {
    trev_dat[rev_dat_size++] = std::move(t[bb].get(0,ix[b]+1));
    b = par[G[bb][0]];
    bb = dpar[bb];
  }
  while( aa != bb ) {
    dat[dat_size++] = std::move(t[aa].get(0,ix[a]+1));
    trev_dat[rev_dat_size++] = std::move(t[bb].get(0,ix[b]+1));
    a = par[G[aa][0]];
    b = par[G[bb][0]];
    aa = dpar[aa];
    bb = dpar[bb];
  }
  mid = std::move(t[aa].get(min(ix[a],ix[b]),max(ix[a],ix[b])+1));
  if( ix[a] > ix[b] ) {
    swap(mid.left,mid.right);
  }
  for( int i = 0; i < rev_dat_size; i++ ) {
    rev_dat[i] = std::move(trev_dat[rev_dat_size-i-1]);
  }
  segtree::dat al=DF;
  for( int i = 0; i < dat_size; i++ ) {
    al = merge(dat[i],al);
  }
  swap(al.left,al.right);
  al = merge(al,mid);
  for( int i = 0; i < rev_dat_size; i++ ) {
    al = merge(al,rev_dat[i]);
  }
  return al.ans;
}

const int S = 11451419;
char buf[S];
int ccc = 0;

inline int getc()
{
  return buf[ccc++];
}

inline int get_i()
{
  int c = getc();
  if( c == '-' ) {
    return -get_i();
  } else {
    int res = c-'0';
    for(;;) {
      c = getc();
      if( isdigit(c) ) {
        res = res*10 + c-'0';
      } else {
        break;
      }
    }
    return res;
  }
}

signed main(void)
{
  int z = read(0,buf,S);
  n = get_i();
  q = get_i();
  //printf("%d %d\n",n,q);
  for( int i = 0; i < n; i++ ) w[i] = get_i();
  for( int i = 0; i < n-1; i++ ) {
    int s,t;
    s = get_i(); t = get_i();
    --s; --t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  memset(par,-1,sizeof(par));
  dfs(0,-1);
  kk = 0;
  dec(0,0);
  kk += 1;
  for( int i = 0; i < kk; i++ ) {
    t[i].init(G[i]);
  }
  for( int i = 0; i < q; i++ ) {
    int a,b,c,d;
    a = get_i(); b = get_i(); c = get_i(); d = get_i();
    --b; --c;
    if( a == 1 ) {
      update(b,c,d);
    } else {
      printf("%lld\n",get(b,c));
    }
  }
  return 0;
}