#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 2e5 + 69;
const int D = 42;
int sum[N][D];
int n, L, a[N], par[N], q;
vector<int> g[N];
void dfs(int v, int p) {
par[v] = p;
for (auto u : g[v]) {
if (u == p)
continue;
dfs(u, v);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> L;
for (int i = 1;i <= n - 1;i++) {
int a, b;
cin >> a >> b;
a += 40;
b += 40;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 41;i <= 40 + n;i++)
cin >> a[i];
for (int i = 1;i <= 40 + n;i++) {
for (int j = 0;j < D;j++)
sum[i][j] = 1;
}
for (int i = 1;i <= 40;i++) {
g[i].push_back(i + 1);
g[i + 1].push_back(i);
}
dfs(1, 0);
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x, d, w;
cin >> x >> d >> w;
x += 40;
int t = x, j = 0;
while (t != 0 && j <= d) {
sum[t][d - j] = (sum[t][d - j] * w) % L;
if (j != d)
sum[t][d - j - 1] = (sum[t][d - j - 1] * w) % L;
j++;
t = par[t];
}
}
else {
int x;
cin >> x;
x += 40;
int ans = a[x];
int t = x, j = 0;
while (t != 0 && j < D) {
ans = (ans * sum[t][j]) % L;
j++;
t = par[t];
}
cout << ans << '\n';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
3 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8792 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
3 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8792 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
3 ms |
8792 KB |
Output is correct |
15 |
Correct |
3 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8792 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
20 |
Correct |
2 ms |
8792 KB |
Output is correct |
21 |
Correct |
2 ms |
8792 KB |
Output is correct |
22 |
Correct |
2 ms |
8848 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
2 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8792 KB |
Output is correct |
27 |
Correct |
3 ms |
8792 KB |
Output is correct |
28 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
413 ms |
84816 KB |
Output is correct |
3 |
Correct |
289 ms |
93604 KB |
Output is correct |
4 |
Correct |
428 ms |
96080 KB |
Output is correct |
5 |
Correct |
485 ms |
93360 KB |
Output is correct |
6 |
Correct |
278 ms |
92916 KB |
Output is correct |
7 |
Correct |
295 ms |
93952 KB |
Output is correct |
8 |
Correct |
268 ms |
93844 KB |
Output is correct |
9 |
Correct |
573 ms |
97276 KB |
Output is correct |
10 |
Correct |
307 ms |
97380 KB |
Output is correct |
11 |
Correct |
432 ms |
93008 KB |
Output is correct |
12 |
Correct |
336 ms |
93380 KB |
Output is correct |
13 |
Correct |
212 ms |
93708 KB |
Output is correct |
14 |
Correct |
195 ms |
94116 KB |
Output is correct |
15 |
Correct |
192 ms |
93236 KB |
Output is correct |
16 |
Correct |
206 ms |
94032 KB |
Output is correct |
17 |
Correct |
200 ms |
94436 KB |
Output is correct |
18 |
Correct |
2 ms |
8792 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
413 ms |
84816 KB |
Output is correct |
3 |
Correct |
289 ms |
93604 KB |
Output is correct |
4 |
Correct |
428 ms |
96080 KB |
Output is correct |
5 |
Correct |
485 ms |
93360 KB |
Output is correct |
6 |
Correct |
278 ms |
92916 KB |
Output is correct |
7 |
Correct |
295 ms |
93952 KB |
Output is correct |
8 |
Correct |
268 ms |
93844 KB |
Output is correct |
9 |
Correct |
573 ms |
97276 KB |
Output is correct |
10 |
Correct |
307 ms |
97380 KB |
Output is correct |
11 |
Correct |
432 ms |
93008 KB |
Output is correct |
12 |
Correct |
336 ms |
93380 KB |
Output is correct |
13 |
Correct |
212 ms |
93708 KB |
Output is correct |
14 |
Correct |
195 ms |
94116 KB |
Output is correct |
15 |
Correct |
192 ms |
93236 KB |
Output is correct |
16 |
Correct |
206 ms |
94032 KB |
Output is correct |
17 |
Correct |
200 ms |
94436 KB |
Output is correct |
18 |
Correct |
2 ms |
8792 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8852 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
389 ms |
93008 KB |
Output is correct |
25 |
Correct |
332 ms |
93700 KB |
Output is correct |
26 |
Correct |
495 ms |
97492 KB |
Output is correct |
27 |
Correct |
357 ms |
93268 KB |
Output is correct |
28 |
Correct |
284 ms |
93380 KB |
Output is correct |
29 |
Correct |
276 ms |
93204 KB |
Output is correct |
30 |
Correct |
261 ms |
94144 KB |
Output is correct |
31 |
Correct |
566 ms |
95828 KB |
Output is correct |
32 |
Correct |
368 ms |
97492 KB |
Output is correct |
33 |
Correct |
404 ms |
93264 KB |
Output is correct |
34 |
Correct |
354 ms |
93576 KB |
Output is correct |
35 |
Correct |
2 ms |
8792 KB |
Output is correct |
36 |
Correct |
2 ms |
8792 KB |
Output is correct |
37 |
Correct |
2 ms |
8792 KB |
Output is correct |
38 |
Correct |
2 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8796 KB |
Output is correct |
40 |
Correct |
2 ms |
8792 KB |
Output is correct |
41 |
Correct |
2 ms |
9048 KB |
Output is correct |
42 |
Correct |
4 ms |
8796 KB |
Output is correct |
43 |
Correct |
3 ms |
8792 KB |
Output is correct |
44 |
Correct |
2 ms |
8792 KB |
Output is correct |
45 |
Correct |
2 ms |
8792 KB |
Output is correct |
46 |
Correct |
2 ms |
8792 KB |
Output is correct |
47 |
Correct |
2 ms |
8792 KB |
Output is correct |
48 |
Correct |
3 ms |
8792 KB |
Output is correct |
49 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
671 ms |
86608 KB |
Output is correct |
3 |
Correct |
788 ms |
84572 KB |
Output is correct |
4 |
Correct |
595 ms |
84980 KB |
Output is correct |
5 |
Correct |
407 ms |
82008 KB |
Output is correct |
6 |
Correct |
384 ms |
81868 KB |
Output is correct |
7 |
Correct |
330 ms |
82000 KB |
Output is correct |
8 |
Correct |
280 ms |
82472 KB |
Output is correct |
9 |
Correct |
652 ms |
84956 KB |
Output is correct |
10 |
Correct |
881 ms |
85172 KB |
Output is correct |
11 |
Correct |
428 ms |
82104 KB |
Output is correct |
12 |
Correct |
491 ms |
81764 KB |
Output is correct |
13 |
Correct |
332 ms |
82324 KB |
Output is correct |
14 |
Correct |
337 ms |
83104 KB |
Output is correct |
15 |
Correct |
2 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8792 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
641 ms |
87272 KB |
Output is correct |
3 |
Correct |
825 ms |
93160 KB |
Output is correct |
4 |
Correct |
581 ms |
93920 KB |
Output is correct |
5 |
Correct |
429 ms |
91984 KB |
Output is correct |
6 |
Correct |
336 ms |
92284 KB |
Output is correct |
7 |
Correct |
322 ms |
91984 KB |
Output is correct |
8 |
Correct |
295 ms |
92012 KB |
Output is correct |
9 |
Correct |
652 ms |
96856 KB |
Output is correct |
10 |
Correct |
792 ms |
95276 KB |
Output is correct |
11 |
Correct |
428 ms |
92580 KB |
Output is correct |
12 |
Correct |
448 ms |
91112 KB |
Output is correct |
13 |
Correct |
348 ms |
92168 KB |
Output is correct |
14 |
Correct |
347 ms |
92752 KB |
Output is correct |
15 |
Correct |
2 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8792 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
3 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8792 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
3 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8792 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
3 ms |
8792 KB |
Output is correct |
15 |
Correct |
3 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8792 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
20 |
Correct |
2 ms |
8792 KB |
Output is correct |
21 |
Correct |
2 ms |
8792 KB |
Output is correct |
22 |
Correct |
2 ms |
8848 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
2 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8792 KB |
Output is correct |
27 |
Correct |
3 ms |
8792 KB |
Output is correct |
28 |
Correct |
2 ms |
8796 KB |
Output is correct |
29 |
Correct |
2 ms |
8792 KB |
Output is correct |
30 |
Correct |
413 ms |
84816 KB |
Output is correct |
31 |
Correct |
289 ms |
93604 KB |
Output is correct |
32 |
Correct |
428 ms |
96080 KB |
Output is correct |
33 |
Correct |
485 ms |
93360 KB |
Output is correct |
34 |
Correct |
278 ms |
92916 KB |
Output is correct |
35 |
Correct |
295 ms |
93952 KB |
Output is correct |
36 |
Correct |
268 ms |
93844 KB |
Output is correct |
37 |
Correct |
573 ms |
97276 KB |
Output is correct |
38 |
Correct |
307 ms |
97380 KB |
Output is correct |
39 |
Correct |
432 ms |
93008 KB |
Output is correct |
40 |
Correct |
336 ms |
93380 KB |
Output is correct |
41 |
Correct |
212 ms |
93708 KB |
Output is correct |
42 |
Correct |
195 ms |
94116 KB |
Output is correct |
43 |
Correct |
192 ms |
93236 KB |
Output is correct |
44 |
Correct |
206 ms |
94032 KB |
Output is correct |
45 |
Correct |
200 ms |
94436 KB |
Output is correct |
46 |
Correct |
2 ms |
8792 KB |
Output is correct |
47 |
Correct |
2 ms |
8792 KB |
Output is correct |
48 |
Correct |
2 ms |
8796 KB |
Output is correct |
49 |
Correct |
2 ms |
8796 KB |
Output is correct |
50 |
Correct |
3 ms |
8852 KB |
Output is correct |
51 |
Correct |
2 ms |
8796 KB |
Output is correct |
52 |
Correct |
389 ms |
93008 KB |
Output is correct |
53 |
Correct |
332 ms |
93700 KB |
Output is correct |
54 |
Correct |
495 ms |
97492 KB |
Output is correct |
55 |
Correct |
357 ms |
93268 KB |
Output is correct |
56 |
Correct |
284 ms |
93380 KB |
Output is correct |
57 |
Correct |
276 ms |
93204 KB |
Output is correct |
58 |
Correct |
261 ms |
94144 KB |
Output is correct |
59 |
Correct |
566 ms |
95828 KB |
Output is correct |
60 |
Correct |
368 ms |
97492 KB |
Output is correct |
61 |
Correct |
404 ms |
93264 KB |
Output is correct |
62 |
Correct |
354 ms |
93576 KB |
Output is correct |
63 |
Correct |
2 ms |
8792 KB |
Output is correct |
64 |
Correct |
2 ms |
8792 KB |
Output is correct |
65 |
Correct |
2 ms |
8792 KB |
Output is correct |
66 |
Correct |
2 ms |
8796 KB |
Output is correct |
67 |
Correct |
2 ms |
8796 KB |
Output is correct |
68 |
Correct |
2 ms |
8792 KB |
Output is correct |
69 |
Correct |
2 ms |
9048 KB |
Output is correct |
70 |
Correct |
4 ms |
8796 KB |
Output is correct |
71 |
Correct |
3 ms |
8792 KB |
Output is correct |
72 |
Correct |
2 ms |
8792 KB |
Output is correct |
73 |
Correct |
2 ms |
8792 KB |
Output is correct |
74 |
Correct |
2 ms |
8792 KB |
Output is correct |
75 |
Correct |
2 ms |
8792 KB |
Output is correct |
76 |
Correct |
3 ms |
8792 KB |
Output is correct |
77 |
Correct |
2 ms |
8792 KB |
Output is correct |
78 |
Correct |
2 ms |
8792 KB |
Output is correct |
79 |
Correct |
671 ms |
86608 KB |
Output is correct |
80 |
Correct |
788 ms |
84572 KB |
Output is correct |
81 |
Correct |
595 ms |
84980 KB |
Output is correct |
82 |
Correct |
407 ms |
82008 KB |
Output is correct |
83 |
Correct |
384 ms |
81868 KB |
Output is correct |
84 |
Correct |
330 ms |
82000 KB |
Output is correct |
85 |
Correct |
280 ms |
82472 KB |
Output is correct |
86 |
Correct |
652 ms |
84956 KB |
Output is correct |
87 |
Correct |
881 ms |
85172 KB |
Output is correct |
88 |
Correct |
428 ms |
82104 KB |
Output is correct |
89 |
Correct |
491 ms |
81764 KB |
Output is correct |
90 |
Correct |
332 ms |
82324 KB |
Output is correct |
91 |
Correct |
337 ms |
83104 KB |
Output is correct |
92 |
Correct |
2 ms |
8792 KB |
Output is correct |
93 |
Correct |
2 ms |
8792 KB |
Output is correct |
94 |
Correct |
2 ms |
8792 KB |
Output is correct |
95 |
Correct |
2 ms |
8792 KB |
Output is correct |
96 |
Correct |
2 ms |
8792 KB |
Output is correct |
97 |
Correct |
2 ms |
8796 KB |
Output is correct |
98 |
Correct |
641 ms |
87272 KB |
Output is correct |
99 |
Correct |
825 ms |
93160 KB |
Output is correct |
100 |
Correct |
581 ms |
93920 KB |
Output is correct |
101 |
Correct |
429 ms |
91984 KB |
Output is correct |
102 |
Correct |
336 ms |
92284 KB |
Output is correct |
103 |
Correct |
322 ms |
91984 KB |
Output is correct |
104 |
Correct |
295 ms |
92012 KB |
Output is correct |
105 |
Correct |
652 ms |
96856 KB |
Output is correct |
106 |
Correct |
792 ms |
95276 KB |
Output is correct |
107 |
Correct |
428 ms |
92580 KB |
Output is correct |
108 |
Correct |
448 ms |
91112 KB |
Output is correct |
109 |
Correct |
348 ms |
92168 KB |
Output is correct |
110 |
Correct |
347 ms |
92752 KB |
Output is correct |
111 |
Correct |
2 ms |
8792 KB |
Output is correct |
112 |
Correct |
2 ms |
8792 KB |
Output is correct |
113 |
Correct |
2 ms |
8792 KB |
Output is correct |
114 |
Correct |
2 ms |
8792 KB |
Output is correct |
115 |
Correct |
2 ms |
8792 KB |
Output is correct |
116 |
Correct |
398 ms |
91152 KB |
Output is correct |
117 |
Correct |
471 ms |
93520 KB |
Output is correct |
118 |
Correct |
600 ms |
97392 KB |
Output is correct |
119 |
Correct |
431 ms |
93312 KB |
Output is correct |
120 |
Correct |
370 ms |
93080 KB |
Output is correct |
121 |
Correct |
372 ms |
93716 KB |
Output is correct |
122 |
Correct |
338 ms |
94140 KB |
Output is correct |
123 |
Correct |
614 ms |
96560 KB |
Output is correct |
124 |
Correct |
829 ms |
95756 KB |
Output is correct |
125 |
Correct |
422 ms |
92240 KB |
Output is correct |
126 |
Correct |
540 ms |
93776 KB |
Output is correct |
127 |
Correct |
544 ms |
94208 KB |
Output is correct |
128 |
Correct |
470 ms |
94708 KB |
Output is correct |
129 |
Correct |
476 ms |
95764 KB |
Output is correct |