#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, D = 41;
int n, mod, q;
int a[N];
vector<int> g[N];
int cnt[N][D];
int par[N];
int mul(int x, int y) { return (x * 1LL * y) % mod; }
void smul(int& x, int y) { x = mul(x, y); }
void dfs(int u, int p) {
par[u] = p;
for(int v : g[u]) {
if(v == p) continue;
dfs(v, u);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> mod;
for(int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i < N; i++) for(int j = 0; j < D; j++) cnt[i][j] = 1;
dfs(1, 0);
cin >> q;
while(q--) {
int t;
cin >> t;
if(t == 1) {
int u, d, w;
cin >> u >> d >> w;
for(int i = d; i >= 0; i--) {
if(u == 1) {
smul(cnt[u][i], w);
continue;
}
smul(cnt[u][i], w);
if(i > 0) smul(cnt[u][i - 1], w);
u = par[u];
}
} else {
int u;
cin >> u;
int res = 1;
for(int i = 0; i < D; i++) {
if(u == 0) break;
smul(res, cnt[u][i]);
u = par[u];
}
cout << res << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
37720 KB |
Output is correct |
2 |
Incorrect |
10 ms |
37720 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
37720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
37720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
37720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
37720 KB |
Output is correct |
2 |
Incorrect |
451 ms |
57424 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
37720 KB |
Output is correct |
2 |
Incorrect |
10 ms |
37720 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |