#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int sz = 45;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, L; cin>>n>>L;
vector<int> g[n + 1];
for (int i = 1; i < n; i++){
int a, b; cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> h(n + 1);
for (int i = 1; i <= n; i++){
cin>>h[i];
}
vector<int> p(n + 1);
function<void(int, int)> dfs = [&](int v, int pr){
p[v] = pr;
for (int i: g[v]){
if (i == pr) continue;
dfs(i, v);
}
};
dfs(1, 0);
vector<vector<int>> T(n + 1, vector<int>(sz, 1));
int q; cin>>q;
while (q--){
int type, x; cin>>type>>x;
if (type == 1){
int d, w; cin>>d>>w;
while (x > 1 && d >= 0){
T[x][d] = (1LL * T[x][d] * w) % L;
if (d) T[x][d - 1] = (1LL * T[x][d - 1] * w) % L;
x = p[x];
d--;
}
for (int i = 0; i <= d; i++){
T[x][i] = (1LL * T[x][i] * w) % L;
}
}
else {
int out = h[x];
for (int i = 0; i < sz; i++){
out = (1LL * out * T[x][i]) % L;
x = p[x];
}
cout<<out<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
476 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
494 ms |
67020 KB |
Output is correct |
3 |
Correct |
346 ms |
67628 KB |
Output is correct |
4 |
Correct |
519 ms |
77148 KB |
Output is correct |
5 |
Correct |
403 ms |
67308 KB |
Output is correct |
6 |
Correct |
321 ms |
66844 KB |
Output is correct |
7 |
Correct |
296 ms |
67600 KB |
Output is correct |
8 |
Correct |
283 ms |
68244 KB |
Output is correct |
9 |
Correct |
631 ms |
82024 KB |
Output is correct |
10 |
Correct |
339 ms |
81236 KB |
Output is correct |
11 |
Correct |
499 ms |
67036 KB |
Output is correct |
12 |
Correct |
362 ms |
67620 KB |
Output is correct |
13 |
Correct |
210 ms |
67988 KB |
Output is correct |
14 |
Correct |
230 ms |
68292 KB |
Output is correct |
15 |
Correct |
218 ms |
67672 KB |
Output is correct |
16 |
Correct |
222 ms |
68060 KB |
Output is correct |
17 |
Correct |
212 ms |
68628 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
494 ms |
67020 KB |
Output is correct |
3 |
Correct |
346 ms |
67628 KB |
Output is correct |
4 |
Correct |
519 ms |
77148 KB |
Output is correct |
5 |
Correct |
403 ms |
67308 KB |
Output is correct |
6 |
Correct |
321 ms |
66844 KB |
Output is correct |
7 |
Correct |
296 ms |
67600 KB |
Output is correct |
8 |
Correct |
283 ms |
68244 KB |
Output is correct |
9 |
Correct |
631 ms |
82024 KB |
Output is correct |
10 |
Correct |
339 ms |
81236 KB |
Output is correct |
11 |
Correct |
499 ms |
67036 KB |
Output is correct |
12 |
Correct |
362 ms |
67620 KB |
Output is correct |
13 |
Correct |
210 ms |
67988 KB |
Output is correct |
14 |
Correct |
230 ms |
68292 KB |
Output is correct |
15 |
Correct |
218 ms |
67672 KB |
Output is correct |
16 |
Correct |
222 ms |
68060 KB |
Output is correct |
17 |
Correct |
212 ms |
68628 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
549 ms |
66992 KB |
Output is correct |
25 |
Correct |
314 ms |
67656 KB |
Output is correct |
26 |
Correct |
552 ms |
81928 KB |
Output is correct |
27 |
Correct |
472 ms |
67380 KB |
Output is correct |
28 |
Correct |
309 ms |
67412 KB |
Output is correct |
29 |
Correct |
312 ms |
67412 KB |
Output is correct |
30 |
Correct |
290 ms |
68036 KB |
Output is correct |
31 |
Correct |
669 ms |
77580 KB |
Output is correct |
32 |
Correct |
355 ms |
81492 KB |
Output is correct |
33 |
Correct |
568 ms |
67096 KB |
Output is correct |
34 |
Correct |
338 ms |
67556 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
780 ms |
79200 KB |
Output is correct |
3 |
Correct |
1044 ms |
75912 KB |
Output is correct |
4 |
Correct |
708 ms |
76280 KB |
Output is correct |
5 |
Correct |
523 ms |
64336 KB |
Output is correct |
6 |
Correct |
364 ms |
64376 KB |
Output is correct |
7 |
Correct |
339 ms |
64556 KB |
Output is correct |
8 |
Correct |
275 ms |
65224 KB |
Output is correct |
9 |
Correct |
727 ms |
74664 KB |
Output is correct |
10 |
Correct |
997 ms |
78184 KB |
Output is correct |
11 |
Correct |
535 ms |
64472 KB |
Output is correct |
12 |
Correct |
663 ms |
64852 KB |
Output is correct |
13 |
Correct |
422 ms |
65616 KB |
Output is correct |
14 |
Correct |
461 ms |
66368 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
697 ms |
76896 KB |
Output is correct |
3 |
Correct |
955 ms |
72768 KB |
Output is correct |
4 |
Correct |
722 ms |
74940 KB |
Output is correct |
5 |
Correct |
609 ms |
65872 KB |
Output is correct |
6 |
Correct |
353 ms |
66028 KB |
Output is correct |
7 |
Correct |
320 ms |
65744 KB |
Output is correct |
8 |
Correct |
281 ms |
65984 KB |
Output is correct |
9 |
Correct |
684 ms |
81164 KB |
Output is correct |
10 |
Correct |
1030 ms |
79668 KB |
Output is correct |
11 |
Correct |
588 ms |
66676 KB |
Output is correct |
12 |
Correct |
660 ms |
65200 KB |
Output is correct |
13 |
Correct |
440 ms |
65980 KB |
Output is correct |
14 |
Correct |
443 ms |
66388 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
476 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
494 ms |
67020 KB |
Output is correct |
31 |
Correct |
346 ms |
67628 KB |
Output is correct |
32 |
Correct |
519 ms |
77148 KB |
Output is correct |
33 |
Correct |
403 ms |
67308 KB |
Output is correct |
34 |
Correct |
321 ms |
66844 KB |
Output is correct |
35 |
Correct |
296 ms |
67600 KB |
Output is correct |
36 |
Correct |
283 ms |
68244 KB |
Output is correct |
37 |
Correct |
631 ms |
82024 KB |
Output is correct |
38 |
Correct |
339 ms |
81236 KB |
Output is correct |
39 |
Correct |
499 ms |
67036 KB |
Output is correct |
40 |
Correct |
362 ms |
67620 KB |
Output is correct |
41 |
Correct |
210 ms |
67988 KB |
Output is correct |
42 |
Correct |
230 ms |
68292 KB |
Output is correct |
43 |
Correct |
218 ms |
67672 KB |
Output is correct |
44 |
Correct |
222 ms |
68060 KB |
Output is correct |
45 |
Correct |
212 ms |
68628 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
549 ms |
66992 KB |
Output is correct |
53 |
Correct |
314 ms |
67656 KB |
Output is correct |
54 |
Correct |
552 ms |
81928 KB |
Output is correct |
55 |
Correct |
472 ms |
67380 KB |
Output is correct |
56 |
Correct |
309 ms |
67412 KB |
Output is correct |
57 |
Correct |
312 ms |
67412 KB |
Output is correct |
58 |
Correct |
290 ms |
68036 KB |
Output is correct |
59 |
Correct |
669 ms |
77580 KB |
Output is correct |
60 |
Correct |
355 ms |
81492 KB |
Output is correct |
61 |
Correct |
568 ms |
67096 KB |
Output is correct |
62 |
Correct |
338 ms |
67556 KB |
Output is correct |
63 |
Correct |
1 ms |
600 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
1 ms |
460 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
1 ms |
348 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
1 ms |
348 KB |
Output is correct |
76 |
Correct |
1 ms |
348 KB |
Output is correct |
77 |
Correct |
1 ms |
344 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
780 ms |
79200 KB |
Output is correct |
80 |
Correct |
1044 ms |
75912 KB |
Output is correct |
81 |
Correct |
708 ms |
76280 KB |
Output is correct |
82 |
Correct |
523 ms |
64336 KB |
Output is correct |
83 |
Correct |
364 ms |
64376 KB |
Output is correct |
84 |
Correct |
339 ms |
64556 KB |
Output is correct |
85 |
Correct |
275 ms |
65224 KB |
Output is correct |
86 |
Correct |
727 ms |
74664 KB |
Output is correct |
87 |
Correct |
997 ms |
78184 KB |
Output is correct |
88 |
Correct |
535 ms |
64472 KB |
Output is correct |
89 |
Correct |
663 ms |
64852 KB |
Output is correct |
90 |
Correct |
422 ms |
65616 KB |
Output is correct |
91 |
Correct |
461 ms |
66368 KB |
Output is correct |
92 |
Correct |
1 ms |
344 KB |
Output is correct |
93 |
Correct |
1 ms |
348 KB |
Output is correct |
94 |
Correct |
1 ms |
348 KB |
Output is correct |
95 |
Correct |
1 ms |
344 KB |
Output is correct |
96 |
Correct |
1 ms |
512 KB |
Output is correct |
97 |
Correct |
0 ms |
348 KB |
Output is correct |
98 |
Correct |
697 ms |
76896 KB |
Output is correct |
99 |
Correct |
955 ms |
72768 KB |
Output is correct |
100 |
Correct |
722 ms |
74940 KB |
Output is correct |
101 |
Correct |
609 ms |
65872 KB |
Output is correct |
102 |
Correct |
353 ms |
66028 KB |
Output is correct |
103 |
Correct |
320 ms |
65744 KB |
Output is correct |
104 |
Correct |
281 ms |
65984 KB |
Output is correct |
105 |
Correct |
684 ms |
81164 KB |
Output is correct |
106 |
Correct |
1030 ms |
79668 KB |
Output is correct |
107 |
Correct |
588 ms |
66676 KB |
Output is correct |
108 |
Correct |
660 ms |
65200 KB |
Output is correct |
109 |
Correct |
440 ms |
65980 KB |
Output is correct |
110 |
Correct |
443 ms |
66388 KB |
Output is correct |
111 |
Correct |
1 ms |
348 KB |
Output is correct |
112 |
Correct |
1 ms |
348 KB |
Output is correct |
113 |
Correct |
1 ms |
348 KB |
Output is correct |
114 |
Correct |
1 ms |
344 KB |
Output is correct |
115 |
Correct |
1 ms |
348 KB |
Output is correct |
116 |
Correct |
520 ms |
65084 KB |
Output is correct |
117 |
Correct |
667 ms |
67632 KB |
Output is correct |
118 |
Correct |
632 ms |
81816 KB |
Output is correct |
119 |
Correct |
519 ms |
67584 KB |
Output is correct |
120 |
Correct |
372 ms |
66896 KB |
Output is correct |
121 |
Correct |
378 ms |
67668 KB |
Output is correct |
122 |
Correct |
304 ms |
68036 KB |
Output is correct |
123 |
Correct |
750 ms |
79068 KB |
Output is correct |
124 |
Correct |
1112 ms |
76612 KB |
Output is correct |
125 |
Correct |
554 ms |
66128 KB |
Output is correct |
126 |
Correct |
779 ms |
67440 KB |
Output is correct |
127 |
Correct |
790 ms |
68192 KB |
Output is correct |
128 |
Correct |
511 ms |
68832 KB |
Output is correct |
129 |
Correct |
553 ms |
69560 KB |
Output is correct |