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 fi first
#define se second
#define keish ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int n, l, q, u, v, t, x, d, w, lim;
vector<int> con[1005][1005];
signed main(){
keish;
cin >> n >> l;
vector<vector<int>> e(n);
for(int i = 1; i < n; i++){
cin >> u >> v; u--, v--;
e[u].push_back(v);
e[v].push_back(u);
}
vector<int> a(n);
for(auto &x : a) cin >> x;
function<void(int, int, int)> dfs = [&](int u, int p, int d){
if(d > lim) return;
for(auto v : e[u]){
if(v == p) continue;
(a[v] *= w) %= l;
dfs(v, u, d + 1);
}
};
cin >> q;
while(q--){
cin >> t;
if(t == 1){
cin >> x >> lim >> w; x--;
(a[x] *= w) %= l;
dfs(x, -1, 1);
}else{
cin >> x; x--;
cout << a[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... |