#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
vector <int> adj[MAXN];
int p[MAXN], h[MAXN], n, l, q;
int lazy[MAXN], lazy2[MAXN];
void fix (int pos, int par) {
p[pos] = par;
for (int j = 0; j < (int)adj[pos].size(); j++) {
if (adj[pos][j] == par) {
adj[pos].erase(adj[pos].begin() + j);
break;
}
}
for (auto j : adj[pos]) {
fix(j, pos);
}
}
int mul (int a, int b) {
return (a * 1ll * b) % l;
}
int main () {
cin >> n >> l;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 1; i <= n; i++) lazy[i] = lazy2[i] = 1;
fix(1, -1);
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x, d, w;
cin >> x >> d >> w;
if (d == 0) {
h[x] = mul(h[x], w);
} else if (d == 1) {
if (p[x] != -1) {
h[p[x]] = mul(h[p[x]], w);
}
h[x] = mul(h[x], w);
lazy[x] = mul(lazy[x], w);
} else if (d == 2) {
if (p[x] == -1) {
lazy2[x] = mul(lazy2[x], w);
h[x] = mul(h[x], w);
} else if (p[p[x]] == -1) {
lazy2[x] = mul(lazy2[x], w);
h[p[x]] = mul(h[p[x]], w);
lazy[p[x]] = mul(lazy[p[x]], w);
} else {
lazy2[x] = mul(lazy2[x], w);
lazy[p[x]] = mul(lazy[p[x]], w);
h[p[x]] = mul(h[p[x]], w);
h[p[p[x]]] = mul(h[p[p[x]]], w);
}
}
} else {
int x;
cin >> x;
int z = h[x];
if (p[x] != -1) {
z = mul(z, lazy[p[x]]);
if (p[p[x]] != -1) {
z = mul(z, lazy2[p[p[x]]]);
}
}
cout << z << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
809 ms |
17968 KB |
Output is correct |
3 |
Correct |
544 ms |
15232 KB |
Output is correct |
4 |
Correct |
627 ms |
22352 KB |
Output is correct |
5 |
Correct |
619 ms |
16516 KB |
Output is correct |
6 |
Correct |
611 ms |
16576 KB |
Output is correct |
7 |
Correct |
627 ms |
16808 KB |
Output is correct |
8 |
Correct |
602 ms |
17208 KB |
Output is correct |
9 |
Correct |
800 ms |
27312 KB |
Output is correct |
10 |
Correct |
485 ms |
23124 KB |
Output is correct |
11 |
Correct |
767 ms |
18048 KB |
Output is correct |
12 |
Correct |
494 ms |
14788 KB |
Output is correct |
13 |
Correct |
459 ms |
15524 KB |
Output is correct |
14 |
Correct |
461 ms |
15560 KB |
Output is correct |
15 |
Correct |
455 ms |
16012 KB |
Output is correct |
16 |
Correct |
472 ms |
15544 KB |
Output is correct |
17 |
Correct |
482 ms |
15944 KB |
Output is correct |
18 |
Correct |
4 ms |
8024 KB |
Output is correct |
19 |
Correct |
3 ms |
8028 KB |
Output is correct |
20 |
Correct |
3 ms |
8028 KB |
Output is correct |
21 |
Correct |
3 ms |
8028 KB |
Output is correct |
22 |
Correct |
3 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
809 ms |
17968 KB |
Output is correct |
3 |
Correct |
544 ms |
15232 KB |
Output is correct |
4 |
Correct |
627 ms |
22352 KB |
Output is correct |
5 |
Correct |
619 ms |
16516 KB |
Output is correct |
6 |
Correct |
611 ms |
16576 KB |
Output is correct |
7 |
Correct |
627 ms |
16808 KB |
Output is correct |
8 |
Correct |
602 ms |
17208 KB |
Output is correct |
9 |
Correct |
800 ms |
27312 KB |
Output is correct |
10 |
Correct |
485 ms |
23124 KB |
Output is correct |
11 |
Correct |
767 ms |
18048 KB |
Output is correct |
12 |
Correct |
494 ms |
14788 KB |
Output is correct |
13 |
Correct |
459 ms |
15524 KB |
Output is correct |
14 |
Correct |
461 ms |
15560 KB |
Output is correct |
15 |
Correct |
455 ms |
16012 KB |
Output is correct |
16 |
Correct |
472 ms |
15544 KB |
Output is correct |
17 |
Correct |
482 ms |
15944 KB |
Output is correct |
18 |
Correct |
4 ms |
8024 KB |
Output is correct |
19 |
Correct |
3 ms |
8028 KB |
Output is correct |
20 |
Correct |
3 ms |
8028 KB |
Output is correct |
21 |
Correct |
3 ms |
8028 KB |
Output is correct |
22 |
Correct |
3 ms |
8028 KB |
Output is correct |
23 |
Correct |
3 ms |
8028 KB |
Output is correct |
24 |
Incorrect |
768 ms |
26272 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Incorrect |
772 ms |
27384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |