#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("heavypath.in");
ofstream out("heavypath.out");
#define ll long long
#define ull unsigned long long
#define pb push_back
const int NMax = 1e5 + 5;
const int arbMax = 4*NMax;
int N,M,nrChain;
int value[NMax],depth[NMax], sub[NMax], chainOf[NMax],
chainOffset[NMax], chainDim[NMax], chainDad[NMax], chainDepth[NMax],
aint[arbMax];
vector<int> v[NMax],chain[NMax];
void read();
void getChains();
void solveQueries();
void dfs(int);
void build(int,int,int,int);
void update(int,int,int,int,int,int);
int query(int,int,int,int,int,int);
int main() {
read();
getChains();
solveQueries();
in.close();out.close();
return 0;
}
void read() {
in>>N>>M;
for (int i=1;i <= N;++i) {
in>>value[i];
}
for (int i=1;i < N;++i) {
int x,y;
in>>x>>y;
v[x].pb(y);
v[y].pb(x);
}
}
void getChains() {
depth[1] = 1;
dfs(1);
for (int i = 1;i <= nrChain;++i) {
reverse(chain[i].begin(), chain[i].end());
chainOffset[i] = chainOffset[i-1] + 4 * chainDim[i-1] + 1;
build(1, 1, chainDim[i], i);
}
}
void dfs(int node) {
sub[node] = 1;
int heavy = 0;
bool leaf = true;
for (int nxt : v[node]) {
if (depth[nxt]) {
continue;
}
leaf = false;
depth[nxt] = depth[node] + 1;
dfs(nxt);
sub[node] += sub[nxt];
if (sub[heavy] < sub[nxt]) {
heavy = nxt;
}
}
if (leaf) {
chain[++nrChain].pb(node);
chainDim[nrChain] = 1;
chainOf[node] = nrChain;
return;
}
chain[ chainOf[heavy] ].pb(node);
++chainDim[ chainOf[heavy] ];
chainOf[node] = chainOf[heavy];
for (int nxt : v[node]) {
if (nxt == heavy || !chainOf[nxt]) {
//if (nxt == heavy || depth[nxt] < depth[node]) {
continue;
}
chainDad[ chainOf[nxt] ] = node;
chainDepth[ chainOf[nxt] ] = depth[node];
}
}
void solveQueries() {
while (M--) {
int tip,x,y;
in>>tip>>x>>y;
if (!tip) {
int cn = chainOf[x];
update(1, 1, chainDim[cn], chainOffset[cn], depth[x] - chainDepth[cn], y);
}
else {
int mx = -1;
while (chainOf[x] != chainOf[y]) {
if (chainDepth[ chainOf[x] ] < chainDepth[ chainOf[y] ]) {
swap(x,y);
}
int cn = chainOf[x];
int val = query(1, 1, chainDim[cn], chainOffset[cn], 1, depth[x] - chainDepth[cn]);
mx = max(mx,val);
x = chainDad[cn];
}
if (depth[x] > depth[y]) {
swap(x,y);
}
int cn = chainOf[x];
int val = query(1, 1, chainDim[cn], chainOffset[cn], depth[x] - chainDepth[cn], depth[y] - chainDepth[cn]);
mx = max(mx,val);
out<<mx<<'\n';
}
}
}
#define mij ((st+dr)>>1)
#define fs (node<<1)
#define ss (fs+1)
void build(int node,int st,int dr,int id) {
int off = chainOffset[id];
if (st == dr) {
aint[node + off] = value[ chain[id][st - 1] ];
return;
}
build(fs, st, mij, id);
build(ss, mij+1, dr, id);
aint[node + off] = max(aint[fs + off], aint[ss + off]);
}
void update(int node,int st,int dr,int off,int pos,int val) {
if (st == dr) {
aint[node + off] = val;
return;
}
if (pos <= mij) {
update(fs, st, mij, off, pos, val);
}
else {
update(ss, mij+1, dr, off, pos, val);
}
aint[node + off] = max(aint[fs + off], aint[ss + off]);
}
int query(int node,int st,int dr,int off,int a,int b) {
if (a <= st && dr <= b) {
return aint[node + off];
}
int ret = 0;
if (a <= mij) {
ret = query(fs, st, mij, off, a, b);
}
if (mij+1 <= b) {
ret = max(ret, query(ss, mij+1, dr, off, a, b));
}
return ret;
}