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;
typedef long long ll;
const int B = 40;
const int MAXN = 2e5 + 40 + 25;
int n, l, p[MAXN];
vector <int> adj[MAXN];
int dp[MAXN][B + 1], dep[MAXN];
int mul (int x, int y) {
return (x * 1ll * y) % l;
}
int h[MAXN];
void dfs (int pos, int par) {
p[pos] = par;
for (auto j : adj[pos]) {
if (j != par) {
dep[j] = 1 + dep[pos];
dfs(j, pos);
}
}
}
void solve () {
cin >> n >> l;
for (int i = 1; i < n; i++) {
int x, y; cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(1, 0);
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
p[1] = n + 1;
for (int i = n + 2; i <= n + 40; i++) {
p[i - 1] = i;
}
for (int i = 1; i <= n + 40; i++) {
for (int j = 0; j <= B; j++) {
dp[i][j] = 1;
}
}
int q; cin >> q;
while (q--) {
int t; cin >> t;
if (t == 1) {
int x, d, w; cin >> x >> d >> w;
for (int i = d; i >= 0; i--) {
dp[x][i] = mul(dp[x][i], w);
if (i) {
dp[x][i - 1] = mul(dp[x][i - 1], w);
}
x = p[x];
}
} else {
int x; cin >> x;
int ret = h[x];
for (int i = 0; i <= B; i++) {
ret = mul(ret, dp[x][i]);
x = p[x];
}
cout << ret << '\n';
}
}
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int tc = 1; //cin >> tc;
while (tc--) solve();
}
# | 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... |