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
using namespace std;
int n, l, d, w;
vector<int> h;
vector<vector<int>> adj;
void dfs(int u, int p=-1, int H=0) {
if(H>d) return;
h[u]=(h[u]*w)%l;
for(int pp : adj[u]) {
if(pp==p) continue;
dfs(pp, u, H+1);
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> l;
adj.resize(n); h.resize(n);
for(int i=1; i<n; i++) {
int u, v; cin >> u >> v;
--u; --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int &p : h) cin >> p;
int q; cin >> q;
while(q--) {
int type, x; cin >> type >> x; --x;
if(type==1) cin >> d >> w, dfs(x);
else cout << h[x] << '\n';
}
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... |