#include <bits/stdc++.h>
using namespace std;
const int N = 200'000 + 10;
int n, L, q;
vector<int> ad[N];
int h[N];
void dfs(int u, int p, int d, int w) {
if (d < 0) return;
h[u] = 1ll * h[u] * w % L;
for (const auto& v : ad[u]) {
if (v == p) continue;
dfs(v, u, d - 1, w);
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> L;
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
ad[u].push_back(v);
ad[v].push_back(u);
}
for (int i = 1; i <= n; ++i) cin >> h[i];
cin >> q;
while (q--) {
int type; cin >> type;
if (type == 1) {
int x, d, w; cin >> x >> d >> w;
dfs(x, -1, d, w);
}
if (type == 2) {
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... |