#include <bits/stdc++.h>
using namespace std;
ifstream fin("heavypath.in");
ofstream fout("heavypath.out");
const int maxn=100005;
vector<int> graf[maxn];
int cost[maxn],sz[maxn],depth[maxn],heavy[maxn],p[maxn],head[maxn],poz[maxn],pos=0,pret,maxim=0,n;
int aint[4*maxn];
void update(int nod,int left,int right)
{
if(right==left)
{
aint[left]=pret;
return;
}
int med=(left+right)/2;
if(pos<=med)
{
update(2*nod,left,med);
}
else
update(2*nod,med,right);
aint[nod]=max(aint[2*nod],aint[2*nod+1]);
}
void constr()
{
int i;
for(i=1;i<=n;++i)
{
pret=cost[i];
pos=poz[i];
update(1,1,n);
}
}
void dfs(int nod,int par)
{
p[nod]=par;
depth[nod]=depth[par]+1;
sz[nod]=1;
int maximum=0;
for(auto a:graf[nod])
{
if(a!=par)
{
dfs(a,nod);
sz[nod]+=sz[a];
if(sz[a]>maximum)
{
maximum=sz[a];
heavy[nod]=a;
}
}
}
cout<<"heavy["<<nod<<"] este "<<heavy[nod]<<'\n';
cout<<"parinte"<<p[nod]<<'\n';
}
void decompose(int nod,int head)
{
poz[nod]=++pos;
if(pos<=n)
cout<<nod<<' '<<pos<<'\n';
if(heavy[nod]>0)
decompose(heavy[nod],head);
for(auto a:graf[nod])
{
if(a!=p[a])
{
if(heavy[nod]!=a)
{
decompose(a,a);
}
}
}
}
void query(int nod,int left,int right,int fleft,int fright)
{
if(fleft>=left && right<=fright)
{
maxim=max(maxim,aint[nod]);
return;
}
int med=(left+right)/2;
if(med>=fleft)
{
query(2*nod,left,med,fleft,fright);
}
if(med+1<=fright)
{
query(2*nod+1,med+1,right,fleft,fright);
}
}
int interogare(int u,int v)
{
int maximum=0;
while(head[u]!=head[v])
{
maxim=0;
if(depth[head[u]]<depth[head[v]])
swap(u,v);
query(1,1,n,head[u],u);
u=p[head[u]];
maximum=max(maximum,maxim);
}
if(depth[u]<depth[v])
swap(u,v);
query(1,1,n,v,u);
maximum=max(maximum,maxim);
return maximum;
}
int main()
{
int m,i,j,u,v,newval;
bool tip;
fin>>n>>m;
for(i=1;i<=n;++i)
fin>>cost[i];
for(i=1;i<=n-1;++i)
{
fin>>u>>v;
graf[u].push_back(v);
graf[v].push_back(u);
}
///algegem 1 ca rad
depth[0]=0;
dfs(1,0);
decompose(1,1);
return 0;
for(i=1;i<=m;++i)
{
fin>>tip;
if(tip==0)
{
fin>>u>>newval;
pret=newval;
pos=u;
update(1,1,n);
}
if(tip==1)
{
///query
fin>>u>>v;
if(u>v)
swap(u,v);
fout<<interogare(u,v);
}
}
return 0;
}