#include <bits/stdc++.h>
using namespace std;
const int kD = 40;
void multSelf(int &x, int y, int mod) {
x = (int64_t)x * y % mod;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, l;
cin >> n >> l;
vector<int> par(1 + n + kD);
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
par[v] = u;
}
par[1] = n + 1;
for (int i = n + 1; i < n + kD; ++i) {
par[i] = i + 1;
}
vector<int> h(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
vector<vector<int>> coef(1 + n + kD, vector<int>(1 + kD, 1));
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int t;
cin >> t;
if (t == 1) {
int x, d, w;
cin >> x >> d >> w;
int node = x, curr = d;
while (curr >= 0) {
multSelf(coef[node][curr], w, l);
node = par[node];
curr -= 1;
}
node = x, curr = d - 1;
while (curr >= 0) {
multSelf(coef[node][curr], w, l);
node = par[node];
curr -= 1;
}
} else {
int x;
cin >> x;
int res = h[x], curr = 0;
while (curr <= kD) {
multSelf(res, coef[x][curr], l);
x = par[x];
curr += 1;
}
cout << res << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
353 ms |
41684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
419 ms |
44496 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |