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 endl "\n"
using namespace std;
const int maxn = 2*1e5+5;
long long n,l,q;
long long type,x,d,w;
long long h[maxn],par[maxn];
long long dp[maxn][42];
vector<int>g[maxn];
long long ans;
void dfs(int beg, int p)
{
par[beg] = p;
for(int nb:g[beg])
{
if(nb!=p) dfs(nb,beg);
}
}
void dfs1(int beg, int d, long long w)
{
if(d<0) return;
dp[beg][d] = (dp[beg][d]*w)%l;
d--;
if(d<0) return;
dp[beg][d] = (dp[beg][d]*w)%l;
if(par[beg]==beg) d--;
dfs1(par[beg],d,w);
}
void dfs2(int beg, int d)
{
if(d>40) return;
ans = (ans*dp[beg][d])%l;
if(beg!=par[beg]) dfs2(par[beg],d+1);
}
void read()
{
cin >> n >> l;
for(int i=1;i<=n;i++)
{
for(int z=0;z<=41;z++) dp[i][z] = 1;
}
int a,b;
for(int i=1;i<n;i++)
{
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i=1;i<=n;i++) cin >> h[i];
dfs(1,1);
cin >> q;
for(int i=1;i<=q;i++)
{
cin >> type >> x;
/*for(int j=1;j<=n;j++)
{
cout << j << "->";
for(int z=0;z<=n;z++)
{
cout << " " << dp[j][z];
}
cout << endl;
}*/
if(type==2)
{
ans = h[x];
dfs2(x,0);
cout << ans << endl;
}
else
{
cin >> d >> w;
dfs1(x,d,w);
}
/*for(int j=1;j<=n;j++)
{
cout << j << "->";
for(int z=0;z<=n;z++)
{
cout << " " << dp[j][z];
}
cout << endl;
}
cout << "+++++++++" << " " << "end query" << endl;*/
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read();
return 0;
}
# | 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... |