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;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,l;
cin >> n >> l;
vector<vector<int>> adj(n+1);
for(int i=1;i<n;i++){
int a,b;cin>>a>>b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
vector<int> H(n+1);
for(int i=1;i<=n;i++)cin>>H[i];
function<void(int,int,int,int)> dfs = [&](int x,int p,int range,int w){
H[x]=(H[x]*w)%l;
if(range==0)return;
for(int&i:adj[x])if(i!=p)dfs(i,x,range-1,w);
};
int q;
cin >> q;
for(int i=1;i<=q;i++){
int type;cin>>type;
if(type==1){
int x,d,w;cin>>x>>d>>w;
dfs(x,0,d,w);
} else {
int x;cin>>x;
cout << H[x] << '\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... |