#include <bits/stdc++.h>
using namespace std;
struct LinkCut {
struct Node {
int p = 0, c[2] = {0, 0}, pp = 0;
bool flip = 0;
int val = 0, dp = 0;
};
vector<Node> T;
LinkCut(int n) : T(n + 1) {}
// SPLAY TREE OPERATIONS START
int dir(int x, int y) { return T[x].c[1] == y; }
void set(int x, int d, int y) {
if (x) {
T[x].c[d] = y; pull(x);
}
if (y) T[y].p = x;
}
void pull(int x) {
if (!x) return;
int &l = T[x].c[0], &r = T[x].c[1];
T[x].dp = max({T[x].val, T[l].dp, T[r].dp});
}
void push(int x) {
if (!x || !T[x].flip) return;
int &l = T[x].c[0], &r = T[x].c[1];
swap(l, r); T[l].flip ^= 1; T[r].flip ^= 1;
T[x].flip = 0;
}
void rotate(int x, int d) {
int y = T[x].p, z = T[y].p, w = T[x].c[d];
swap(T[x].pp, T[y].pp);
set(y, !d, w);
set(x, d, y);
set(z, dir(z, y), x);
}
void refresh(int x) {
if (!x) return;
refresh(T[x].p);
push(x);
}
void splay(int x) {
// refresh(x);
for (push(x); T[x].p;) {
int y = T[x].p, z = T[y].p;
push(z); push(y); push(x);
int dx = dir(y, x), dy = dir(z, y);
if (!z) {
rotate(x, !dx);
}
else if (dx == dy)
rotate(y, !dx), rotate(x, !dx);
else
rotate(x, dy), rotate(x, dx);
}
}
// SPLAY TREE OPERATIONS END
void Link(int u, int v) {
// cerr << "Link: " << u << " " << v << endl;
MakeRoot(v);
T[v].pp = u;
}
void dump2() {
for (int i = 1; i < (int)T.size(); ++i) {
cerr << i << ": " << T[i].c[0] << " " << T[i].c[1] << " "
<< T[i].p << " " << T[i].pp << endl;
}
}
/// Move u to root of represented tree.
void MakeRoot(int u) {
// cerr << "MakeRoot: " << u << endl;
Access(u);
assert(T[u].p == 0);
// cerr << "REVERSING: "; dump(T[u].c[0]); cerr << endl;
int l = T[u].c[0];
T[l].flip ^= 1;
swap(T[l].p, T[l].pp);
push(T[u].c[0]);
set(u, 0, 0);
// cerr << "----------" << endl;
}
void Access(int _u) {
// cerr << "Access: " << _u << endl;
for (int v = 0, u = _u; u; u = T[v = u].pp) {
// cerr << "relinking: " << u << " to " << v << endl;
splay(u); splay(v);
// dump(u); cerr << " | "; dump(v); cerr << endl;
int r = T[u].c[1];
T[v].pp = 0;
swap(T[r].p, T[r].pp);
set(u, 1, v);
}
splay(_u);
// Dump();
// cerr << "------------" << endl;
}
void Update(int u, int val) {
// cerr << "Update: " << u << " " << val << endl;
splay(u);
T[u].val = val;
pull(u);
// Dump();
}
int Query(int u, int v) {
// cerr << "Query: " << u << " " << v << endl;
MakeRoot(u);
// cerr << "MADE ROOT IN " << u << endl;
// Dump();
Access(v);
// cerr << "ACCESSED " << v << endl;
// Dump();
// splay(v);
// cerr << "SPLAYED " << v << endl;
// Dump();
// Dump();
return T[v].dp;
}
// void Dump() {
// for (int i = 1; i < (int)T.size(); ++i) {
// if (T[i].p) continue;
// cerr << "(" << i << "): "; dump(i);
// cerr << " --> " << T[i].pp << endl;
// }
// }
void dump(int x) {
if (!x) return;
if (T[x].p) assert(!T[x].pp);
push(x);
dump(T[x].c[0]);
cerr << x << " ";
dump(T[x].c[1]);
}
void Dump() {
for (int i = 1; i < (int)T.size(); ++i) {
if (T[i].p) continue;
cerr << T[i].pp << " <-- ";
dump(i);
cerr << "(dp: " << T[i].dp << ")";
cerr << endl;
}
cerr << endl;
}
};
struct Brut {
vector<set<int>> graph;
vector<int> val;
Brut(int n) : graph(n + 1), val(n + 1) {};
void Link(int a, int b) {
graph[a].insert(b);
graph[b].insert(a);
}
int Query(int a, int b) {
vector<int> dp(graph.size(), -1);
vector<int> q;
auto push = [&](int node, int x) {
if (dp[node] != -1) return;
dp[node] = x;
q.push_back(node);
};
push(a, val[a]);
for (int i = 0; i < (int)q.size(); ++i) {
for (auto vec : graph[q[i]])
push(vec, max(val[vec], dp[q[i]]));
}
return dp[b];
}
void Update(int node, int x) { val[node] = x; }
};
void Test() {
int N = 6, V = 10;
while (true) {
int n = rand() % N + 1;
LinkCut lc(n);
Brut brut(n);
for (int i = 1; i < n; ++i) {
int p = rand() % i;
lc.Link(p + 1, i + 1);
brut.Link(p + 1, i + 1);
}
vector<int> val(n);
for (int i = 0; i < n; ++i) {
val[i] = rand() % V + 1;
lc.T[i + 1].val = val[i];
brut.val[i + 1] = val[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cerr << "_____________________________________" << endl;
cerr << "QUERY: " << i + 1 << " " << j + 1 << endl;
int lcq = lc.Query(i + 1, j + 1);
int brutq = brut.Query(i + 1, j + 1);
if (lcq != brutq) {
cerr << "ERROR" << endl;
cerr << n << endl;
for (int i = 0; i < n; ++i) {
cerr << val[i] << " ";
}
cerr << endl;
for (int i = 1; i <= n; ++i) {
for (auto vec : brut.graph[i]) {
if (i <= vec) {
cout << i << " " << vec << endl;
}
}
}
cerr << endl;
cerr << i + 1 << " " << j + 1 << endl;
cerr << "BRUT: " << brutq << endl;
cerr << "LC: " << lcq << endl;
exit(-1);
}
}
}
}
}
int main() {
// Test();
ifstream cin("heavypath.in");
ofstream cout("heavypath.out");
int n, m; cin >> n >> m;
LinkCut lc(n);
for (int i = 1; i <= n; ++i) {
cin >> lc.T[i].val;
}
for (int i = 1; i < n; ++i) {
int a, b; cin >> a >> b;
lc.Link(a, b);
}
for (int i = 0; i < m; ++i) {
int t, a, b; cin >> t >> a >> b;
if (t == 0) lc.Update(a, b);
else cout << lc.Query(a, b) << '\n';
}
return 0;
}