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>
using namespace std;
const int nx=2e5+5;
#define ll long long
ll n, u, v, q, l, h[nx], lz[nx], pa[nx], t, x, ds, w;
vector<ll> d[nx];
void dfs(int u, int p)
{
pa[u]=p;
for (auto v:d[u]) if (v!=p) dfs(v, u);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>l;
for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
for (int i=1; i<=n; i++) cin>>h[i], lz[i]=1;
dfs(1, 1);
cin>>q;
while (q--)
{
cin>>t;
if (t==1)
{
cin>>x>>ds>>w;
if (ds==0) h[x]=(h[x]*w)%l;
else
{
h[x]=(h[x]*w)%l;
if (pa[x]!=x) h[pa[x]]=(h[pa[x]]*w)%l;
lz[x]=(lz[x]*w)%l;
}
}
else
{
cin>>u;
if (pa[u]==u) cout<<h[u]<<'\n';
else cout<<(h[u]*lz[pa[u]])%l<<'\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... |