#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=2e5+5;
int n,l,q,par[N],init[N],tag[N][41];
vi adj[N];
void dfs(int u, int p=-1){
for(int v:adj[u]) if(v!=p){
par[v]=u;
dfs(v,u);
}
}
void solve(){
cin>>n>>l;
rep(i,n-1){
int u,v; cin>>u>>v;
adj[u].eb(v); adj[v].eb(u);
}
foru(i,1,n){
cin>>init[i];
}
dfs(1);
foru(i,1,n) foru(j,0,40) tag[i][j]=1;
cin>>q;
foru(i,1,q){
int t; cin>>t;
if(t==1){
int x,d,w; cin>>x>>d>>w;
while(x>0 && d>=0){
if(par[x]>0 && d>0){
tag[x][d]=1LL*tag[x][d]*w%l;
tag[x][d-1]=1LL*tag[x][d-1]*w%l;
} else{
foru(j,0,d){
tag[x][j]=1LL*tag[x][j]*w%l;
}
}
--d; x=par[x];
}
} else if(t==2){
int x,d=0; cin>>x;
int res=init[x]%l;
while(x>0 && d<=40){
res=1LL*res*tag[x][d] % l;
++d; x=par[x];
}
cout<<res<<'\n';
} else{
assert(0);
}
}
}
int32_t main(){
#define task "test"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
foru(i,1,tc){
solve();
}
}
Compilation message (stderr)
sprinkler.cpp: In function 'int32_t main()':
sprinkler.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |