#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[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 |
8028 KB |
Output is correct |
2 |
Correct |
774 ms |
18004 KB |
Output is correct |
3 |
Correct |
537 ms |
15004 KB |
Output is correct |
4 |
Correct |
678 ms |
22360 KB |
Output is correct |
5 |
Correct |
666 ms |
16500 KB |
Output is correct |
6 |
Correct |
666 ms |
16336 KB |
Output is correct |
7 |
Correct |
671 ms |
16964 KB |
Output is correct |
8 |
Correct |
653 ms |
17028 KB |
Output is correct |
9 |
Correct |
812 ms |
26924 KB |
Output is correct |
10 |
Correct |
551 ms |
23384 KB |
Output is correct |
11 |
Correct |
804 ms |
18236 KB |
Output is correct |
12 |
Correct |
541 ms |
14932 KB |
Output is correct |
13 |
Correct |
547 ms |
15544 KB |
Output is correct |
14 |
Correct |
523 ms |
15660 KB |
Output is correct |
15 |
Correct |
508 ms |
15600 KB |
Output is correct |
16 |
Correct |
535 ms |
15396 KB |
Output is correct |
17 |
Correct |
532 ms |
16208 KB |
Output is correct |
18 |
Correct |
3 ms |
8028 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 |
8028 KB |
Output is correct |
2 |
Correct |
774 ms |
18004 KB |
Output is correct |
3 |
Correct |
537 ms |
15004 KB |
Output is correct |
4 |
Correct |
678 ms |
22360 KB |
Output is correct |
5 |
Correct |
666 ms |
16500 KB |
Output is correct |
6 |
Correct |
666 ms |
16336 KB |
Output is correct |
7 |
Correct |
671 ms |
16964 KB |
Output is correct |
8 |
Correct |
653 ms |
17028 KB |
Output is correct |
9 |
Correct |
812 ms |
26924 KB |
Output is correct |
10 |
Correct |
551 ms |
23384 KB |
Output is correct |
11 |
Correct |
804 ms |
18236 KB |
Output is correct |
12 |
Correct |
541 ms |
14932 KB |
Output is correct |
13 |
Correct |
547 ms |
15544 KB |
Output is correct |
14 |
Correct |
523 ms |
15660 KB |
Output is correct |
15 |
Correct |
508 ms |
15600 KB |
Output is correct |
16 |
Correct |
535 ms |
15396 KB |
Output is correct |
17 |
Correct |
532 ms |
16208 KB |
Output is correct |
18 |
Correct |
3 ms |
8028 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 |
Incorrect |
2 ms |
8024 KB |
Output isn't correct |
24 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |