#include #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pairP; class LCA{ public: vector>>E; vector>par; vectord1; vectord2; int MAX_LOG=22; int n; LCA(){} LCA(int N){ n=N; E=vector>>(n); par=vector>(MAX_LOG,vector(n)); d1=vector(n); d2=vector(n); } void add_edge(int a,int b,int c){ E[a].push_back(make_pair(c,b)); E[b].push_back(make_pair(c,a)); } void add_edge(int a,int b){ E[a].push_back(make_pair(1,b)); E[b].push_back(make_pair(1,a)); } private: void dfs(int u,int p,int a,long long b){ par[0][u]=p;d1[u]=a;d2[u]=b; for(auto&v:E[u]){ if(v.second!=p)dfs(v.second,u,a+1,b+v.first); } } bool flag=false; void init(){ dfs(0,-1,0,0); for(int i=1;id1[v])swap(u,v); for(int i=0;i>i&1)v=par[i][v]; } if(u==v)return u; for(int i=MAX_LOG-1;i>=0;i--){ if(par[i][u]!=par[i][v]){ u=par[i][u]; v=par[i][v]; } } return par[0][u]; } long long dist(int u,int v){ int l=lca(u,v); return d2[u]+d2[v]-d2[l]*2; } }; LCA lca; vectorE[200000],G[200000]; bool used[200000]; int N; int centroid; int sz[200000]; int par[200000]; int id[200000]; ll sum1[200000],cnt1[200000]; vectorsum2[200000],cnt2[200000]; void szdfs(int v,int p){ sz[v]=1; for(int u:E[v]){ if(u==p||used[u])continue; szdfs(u,v); sz[v]+=sz[u]; } } void search_centroid(int v,int p){ bool ok=true; for(int u:E[v]){ if(u==p||used[u])continue; search_centroid(u,v); if(sz[u]>N/2)ok=false; } if(N-sz[v]>N/2)ok=false; if(ok)centroid=v; } void solve(int v,int p){ szdfs(v,-1); N=sz[v]; search_centroid(v,-1); int s=centroid; used[s]=true; par[s]=p; if(p!=-1)G[p].push_back(s); for(int u:E[s]){ if(used[u])continue; solve(u,s); } } void solve2(int s){ used[s]=true; int g=0; rep(i,E[s].size()){ int u=E[s][i]; if(used[u])continue; sum2[s].push_back({}); cnt2[s].push_back({}); id[G[s][g]]=g; g++; } for(int u:G[s]){ solve2(u); } } void update(int x,int y){ int X=x; int prv=-1; while(x!=-1){ int d=lca.dist(X,x); sum1[x]+=d*y;cnt1[x]+=y; if(prv!=-1)sum2[x][prv]+=d*y,cnt2[x][prv]+=y; prv=id[x]; x=par[x]; } } ll query(int x){ ll ans=0; int X=x; int prv=-1; while(x!=-1){ ll d=lca.dist(X,x); ans+=d*cnt1[x]; ans+=sum1[x]; if(prv!=-1){ ans-=sum2[x][prv]; ans-=d*cnt2[x][prv]; } prv=id[x]; x=par[x]; } return ans; } int c[200000]; int main(){ int n,K,q;cin>>n>>K>>q; rep(i,K){ scanf("%d",&c[i]),c[i]--; } lca=LCA(n); rep(i,n-1){ int a,b;scanf("%d%d",&a,&b);a--;b--; E[a].push_back(b); E[b].push_back(a); lca.add_edge(a,b); } solve(0,-1); memset(used,false,sizeof(used)); solve2(find(par,par+n,-1)-par); rep(i,K)update(c[i],1); rep(i,q){ int ty;scanf("%d",&ty); if(ty==1){ int p,d;scanf("%d%d",&p,&d);p--;d--; update(c[p],-1); c[p]=d; update(c[p],1); } else{ int d;scanf("%d",&d);d--; printf("%lld\n",query(d)); } } }