//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef pair P1; typedef pair P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i,x) for(int i=0;i void dmp(T a){ rep(i,a.size()) cout << a[i] << " "; cout << endl; } template bool chmax(T&a, T b){ if(a < b){ a = b; return 1; } return 0; } template bool chmin(T&a, T b){ if(a > b){ a = b; return 1; } return 0; } template void g(T &a){ cin >> a; } template void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 998244353; template void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } #define SZ 100005 vectoredge[SZ]; int up[20][SZ],dep[SZ]; struct dbling{ bool ready = 0; void dfs(int v,int u,int d){ up[0][v] = u; dep[v] = d; rep(i,edge[v].size()){ if(edge[v][i] == u) continue; dfs(edge[v][i], v, d+1); } } void prepare(){ dfs(1,-1,0); rep(j,19){ rep(i,SZ){ if(up[j][i] == -1) up[j+1][i] = up[j][i]; else up[j+1][i] = up[j][up[j][i]]; } } ready = 1; } int get(int a,int b){ if(dep[a] > dep[b]) swap(a,b); int D = dep[b]-dep[a]; rep(i,20){ if(((D>>i)&1)) b = up[i][b]; } if(a == b) return a; for(int i=19;i>=0;i--){ if(up[i][a] != up[i][b]){ a = up[i][a]; b = up[i][b]; } } return up[0][a]; } int get_dist(int a,int b){ int c = get(a,b); return dep[a]+dep[b]-2*dep[c]; } int get_dist(int a,int b,int c){ //assuming c is lca of (a,b) return dep[a]+dep[b]-2*dep[c]; } int go_up(int v,int a){ if(dep[v] < a) return -1; rep(i,20) if(((a>>i)&1)) v = up[i][v]; return v; } //a ---- b //と並べたときのx番目 (1-indexed) //存在しない場合は-1を返す //verified : opencup Warsaw I int v_on_path(int a,int b,int x){ int c = get(a,b); int d = get_dist(a,b,c); if(x <= 0 || x > d+1) return -1; if(x <= dep[a]-dep[c]+1){ return go_up(a, x-1); } else{ x = d+2-x; return go_up(b, x-1); } } }kaede; int n, k, q, c[100005]; int cnt[100005]; constexpr int B = 334; vectorQ; ll sum[100005]; int sub[100005]; void dfs(int v, int u, int d){ sum[1] += 1LL * d * cnt[v]; rep(i, edge[v].size()){ if(edge[v][i] == u) continue; dfs(edge[v][i], v, d+1); sub[v] += sub[edge[v][i]]; } sub[v] += cnt[v]; } void dfs2(int v, int u){ rep(i, edge[v].size()){ if(edge[v][i] == u) continue; sum[edge[v][i]] = sum[v] + k - 2*sub[edge[v][i]]; dfs2(edge[v][i], v); } } int main(){ scanf("%d%d%d", &n, &k, &q); repn(i, k){ scanf("%d", &c[i]); } rep(i, n-1){ int a, b; scanf("%d%d", &a, &b); edge[a].pb(b); edge[b].pb(a); } kaede.prepare(); rep(i, q){ int ty; scanf("%d", &ty); int a, b = -1; if(ty == 1) scanf("%d%d", &a, &b); else scanf("%d", &a); Q.pb(mp(ty, mp(a, b))); } for(int i=0;ivec; for(int j=i;jgen; rep(i, vec.size()) gen.pb(c[vec[i]]); for(int j=i;j