1 #include<cstdio>
2
3 #include<cstdlib>
4
5 #include<cmath>
6
7 #include<cstring>
8
9 #include<algorithm>
10
11 #include<iostream>
12
13 #include<vector>
14
15 #include<map>
16
17 #include<set>
18
19 #include<queue>
20
21 #include<string>
22
23 #define inf 1000000000
24
25 #define maxn 200000+5
26
27 #define maxm 500+100
28
29 #define eps 1e-10
30
31 #define ll long long
32
33 #define pa pair<int,int>
34
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42
43 #define mod 1000000007
44
45 using namespace std;
46
47 inline int read()
48
49 {
50
51 int x=0,f=1;char ch=getchar();
52
53 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
54
55 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
56
57 return x*f;
58
59 }
60 int n,m,q,rt,tot,dep[maxn],head[maxn],s[maxn],f[maxn][20],w[maxn],id[maxn];
61 int l[maxn],r[maxn],top[maxn],son[maxn];
62 struct edge{int go,next;}e[2*maxn];
63 struct seg{int l,r,mi,tag;}t[4*maxn];
64 inline void insert(int x,int y)
65 {
66 e[++tot]=(edge){y,head[x]};head[x]=tot;
67 e[++tot]=(edge){x,head[y]};head[y]=tot;
68 }
69 inline void dfs(int x)
70 {
71 for1(i,18)if((1<<i)<=dep[x])f[x][i]=f[f[x][i-1]][i-1];else break;
72 s[x]=1;
73 for(int i=head[x],y=son[x]=0;i;i=e[i].next)
74 if(!s[y=e[i].go])
75 {
76 dep[y]=dep[x]+1;f[y][0]=x;
77 dfs(y);
78 s[x]+=s[y];
79 if(s[y]>s[son[x]])son[x]=y;
80 }
81 }
82 inline void dfs2(int x,int chain)
83 {
84 l[x]=++m;id[m]=x;top[x]=chain;
85 if(son[x])dfs2(son[x],chain);
86 for(int i=head[x],y;i;i=e[i].next)
87 if(!l[y=e[i].go]&&y!=son[x])dfs2(y,y);
88 r[x]=m;
89 }
90 inline void pushup(int k)
91 {
92 t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);
93 }
94 inline void update(int k,int z)
95 {
96 t[k].mi=t[k].tag=z;
97 }
98 inline void pushdown(int k)
99 {
100 if(t[k].tag==-1)return;
101 update(k<<1,t[k].tag);
102 update(k<<1|1,t[k].tag);
103 t[k].tag=-1;
104 }
105 inline void build(int k,int l,int r)
106 {
107 t[k].l=l;t[k].r=r;int mid=(l+r)>>1;t[k].tag=-1;
108 if(l==r){t[k].mi=w[id[l]];return;}
109 build(k<<1,l,mid);build(k<<1|1,mid+1,r);
110 pushup(k);
111 }
112 inline void change(int k,int x,int y,int z)
113 {
114 int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
115 if(l==x&&r==y){update(k,z);return;}
116 pushdown(k);
117 if(y<=mid)change(k<<1,x,y,z);
118 else if(x>mid)change(k<<1|1,x,y,z);
119 else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z);
120 pushup(k);
121 }
122 inline int query(int k,int x,int y)
123 {
124 int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
125 if(l==x&&r==y)return t[k].mi;
126 pushdown(k);
127 if(y<=mid)return query(k<<1,x,y);
128 else if(x>mid)return query(k<<1|1,x,y);
129 else return min(query(k<<1,x,mid),query(k<<1|1,mid+1,y));
130 }
131
132 int main()
133
134 {
135
136 freopen("input.txt","r",stdin);
137
138 freopen("output.txt","w",stdout);
139
140 n=read();q=read();
141 for1(i,n-1)insert(read(),read());
142 dfs(1);
143 dfs2(1,1);
144 for1(i,n)w[i]=read();
145 build(1,1,m);
146 rt=read();
147 while(q--)
148 {
149 int ch=read();
150 if(ch==1)rt=read();
151 else if(ch==2)
152 {
153 int x=read(),y=read(),z=read();
154 while(top[x]!=top[y])
155 {
156 if(dep[top[x]]<dep[top[y]])swap(x,y);
157 change(1,l[top[x]],l[x],z);
158 x=f[top[x]][0];
159 }
160 if(dep[x]>dep[y])swap(x,y);
161 change(1,l[x],l[y],z);
162 }
163 else
164 {
165 int x=read();
166 if(x==rt)printf("%d\n",t[1].mi);
167 else if(l[x]<=l[rt]&&r[x]>=r[rt])
168 {
169 int t=dep[rt]-dep[x]-1,y=rt,ans=inf;
170 for3(i,18,0)if(t&(1<<i))y=f[y][i];
171 if(1<=l[y]-1)ans=min(ans,query(1,1,l[y]-1));
172 if(r[y]+1<=n)ans=min(ans,query(1,r[y]+1,n));
173 printf("%d\n",ans);
174 }else printf("%d\n",query(1,l[x],r[x]));
175 }
176 }
177
178 return 0;
179
180 }