This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=2e5+5;
vector <int> g[N];
int p[N];
int dp[N][50];
void dfs(int v,int par){
p[v]=par;
for(auto to : g[v]){
if(to!=par)dfs(to,v);
}
}
signed main(){
int n,l;
cin>>n>>l;
for(int i=0;i<n-1;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
for(int i=1;i<=n;i++){
for(int j=0;j<=40;j++){
dp[i][j]=1;
}
}
dfs(1,0);
vector <int> h(n+1);
for(int i=1;i<=n;i++){
cin>>h[i];
dp[i][0]=h[i];
}
int q;cin>>q;
while(q--){
int type,v,d,x;
cin>>type;
if(type==1){
cin>>v>>d>>x;
while(v>=1 && d>=0){
dp[v][d]=(dp[v][d])*x%l;
d--;
if(d<0)break;
dp[v][d]=(dp[v][d])*x%l;
if(p[v]!=0)v=p[v];
else{
d--;
if(d<0)break;
}
}
}
else{
cin>>v;
int ans=1;
for(int i=0;i<=40;i++){
if(v>=1)ans=ans*dp[v][i]%l;
v=p[v];
}
cout<<ans<<"\n";
}
}
}
# | 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... |