#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int D = 41;
const int N = 2e5 + 5;
int dp[N][D];
int parent[N];
vector<int> g[N];
void dfs(int v, int p) {
parent[v] = p;
for (int u : g[v]) if (u != p) dfs(u, v);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, l;
cin >> n >> l;
auto mul = [&](int x, int y) {
return (int) ((long long) x * y % l);
};
for(int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 0);
for (int i = 1; i <= n; ++i) {
fill(dp[i], dp[i] + D, 1);
}
for (int i = 1; i <= n; ++i) {
cin >> dp[i][0];
}
int q;
cin >> q;
while (q--) {
int t, v;
cin >> t >> v;
if (t == 1) {
int d, w;
cin >> d >> w;
while (d > 0 && v != 1) {
dp[v][d] = mul(dp[v][d], w);//if the distance is d - 1, to parent will be d + 1
dp[v][d - 1] = mul(dp[v][d - 1], w);
d--;
v = parent[v];
}
for (int i = 0; i <= d; ++i) {
dp[v][i] = mul(dp[v][i], w);
}
} else {
int ans = 1;
for (int i = 0; i < D && v; ++i, v = parent[v]) {
ans = mul(ans, dp[v][i]);
}
cout << ans << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6744 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
2 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6744 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
1 ms |
6744 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
2 ms |
6744 KB |
Output is correct |
25 |
Correct |
2 ms |
6744 KB |
Output is correct |
26 |
Correct |
3 ms |
6896 KB |
Output is correct |
27 |
Correct |
2 ms |
6744 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
363 ms |
47884 KB |
Output is correct |
3 |
Correct |
244 ms |
56704 KB |
Output is correct |
4 |
Correct |
338 ms |
58956 KB |
Output is correct |
5 |
Correct |
281 ms |
56260 KB |
Output is correct |
6 |
Correct |
212 ms |
55888 KB |
Output is correct |
7 |
Correct |
232 ms |
56704 KB |
Output is correct |
8 |
Correct |
183 ms |
57300 KB |
Output is correct |
9 |
Correct |
427 ms |
60240 KB |
Output is correct |
10 |
Correct |
282 ms |
60440 KB |
Output is correct |
11 |
Correct |
339 ms |
56368 KB |
Output is correct |
12 |
Correct |
212 ms |
56400 KB |
Output is correct |
13 |
Correct |
160 ms |
56776 KB |
Output is correct |
14 |
Correct |
159 ms |
57288 KB |
Output is correct |
15 |
Correct |
167 ms |
56720 KB |
Output is correct |
16 |
Correct |
160 ms |
57168 KB |
Output is correct |
17 |
Correct |
169 ms |
57680 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
2 ms |
6744 KB |
Output is correct |
20 |
Correct |
2 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
363 ms |
47884 KB |
Output is correct |
3 |
Correct |
244 ms |
56704 KB |
Output is correct |
4 |
Correct |
338 ms |
58956 KB |
Output is correct |
5 |
Correct |
281 ms |
56260 KB |
Output is correct |
6 |
Correct |
212 ms |
55888 KB |
Output is correct |
7 |
Correct |
232 ms |
56704 KB |
Output is correct |
8 |
Correct |
183 ms |
57300 KB |
Output is correct |
9 |
Correct |
427 ms |
60240 KB |
Output is correct |
10 |
Correct |
282 ms |
60440 KB |
Output is correct |
11 |
Correct |
339 ms |
56368 KB |
Output is correct |
12 |
Correct |
212 ms |
56400 KB |
Output is correct |
13 |
Correct |
160 ms |
56776 KB |
Output is correct |
14 |
Correct |
159 ms |
57288 KB |
Output is correct |
15 |
Correct |
167 ms |
56720 KB |
Output is correct |
16 |
Correct |
160 ms |
57168 KB |
Output is correct |
17 |
Correct |
169 ms |
57680 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
2 ms |
6744 KB |
Output is correct |
20 |
Correct |
2 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
1 ms |
6748 KB |
Output is correct |
24 |
Correct |
321 ms |
56152 KB |
Output is correct |
25 |
Correct |
224 ms |
56688 KB |
Output is correct |
26 |
Correct |
334 ms |
60452 KB |
Output is correct |
27 |
Correct |
321 ms |
56400 KB |
Output is correct |
28 |
Correct |
232 ms |
56400 KB |
Output is correct |
29 |
Correct |
217 ms |
56080 KB |
Output is correct |
30 |
Correct |
182 ms |
57072 KB |
Output is correct |
31 |
Correct |
434 ms |
59216 KB |
Output is correct |
32 |
Correct |
248 ms |
60752 KB |
Output is correct |
33 |
Correct |
353 ms |
55888 KB |
Output is correct |
34 |
Correct |
282 ms |
56636 KB |
Output is correct |
35 |
Correct |
2 ms |
6744 KB |
Output is correct |
36 |
Correct |
1 ms |
6744 KB |
Output is correct |
37 |
Correct |
2 ms |
6744 KB |
Output is correct |
38 |
Correct |
2 ms |
6744 KB |
Output is correct |
39 |
Correct |
2 ms |
6748 KB |
Output is correct |
40 |
Correct |
2 ms |
6744 KB |
Output is correct |
41 |
Correct |
1 ms |
6748 KB |
Output is correct |
42 |
Correct |
2 ms |
6744 KB |
Output is correct |
43 |
Correct |
1 ms |
6744 KB |
Output is correct |
44 |
Correct |
2 ms |
6744 KB |
Output is correct |
45 |
Correct |
2 ms |
6744 KB |
Output is correct |
46 |
Correct |
2 ms |
6944 KB |
Output is correct |
47 |
Correct |
2 ms |
6744 KB |
Output is correct |
48 |
Correct |
1 ms |
6748 KB |
Output is correct |
49 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
464 ms |
49372 KB |
Output is correct |
3 |
Correct |
494 ms |
56912 KB |
Output is correct |
4 |
Correct |
417 ms |
56656 KB |
Output is correct |
5 |
Correct |
321 ms |
53544 KB |
Output is correct |
6 |
Correct |
232 ms |
53568 KB |
Output is correct |
7 |
Correct |
246 ms |
53560 KB |
Output is correct |
8 |
Correct |
189 ms |
54108 KB |
Output is correct |
9 |
Correct |
461 ms |
56144 KB |
Output is correct |
10 |
Correct |
525 ms |
57456 KB |
Output is correct |
11 |
Correct |
338 ms |
53028 KB |
Output is correct |
12 |
Correct |
337 ms |
53804 KB |
Output is correct |
13 |
Correct |
302 ms |
54608 KB |
Output is correct |
14 |
Correct |
309 ms |
55376 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
1 ms |
6744 KB |
Output is correct |
17 |
Correct |
1 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
459 ms |
50772 KB |
Output is correct |
3 |
Correct |
539 ms |
56656 KB |
Output is correct |
4 |
Correct |
437 ms |
57428 KB |
Output is correct |
5 |
Correct |
328 ms |
54840 KB |
Output is correct |
6 |
Correct |
304 ms |
55120 KB |
Output is correct |
7 |
Correct |
237 ms |
54848 KB |
Output is correct |
8 |
Correct |
189 ms |
55232 KB |
Output is correct |
9 |
Correct |
433 ms |
59728 KB |
Output is correct |
10 |
Correct |
554 ms |
58192 KB |
Output is correct |
11 |
Correct |
350 ms |
55588 KB |
Output is correct |
12 |
Correct |
371 ms |
54080 KB |
Output is correct |
13 |
Correct |
297 ms |
54796 KB |
Output is correct |
14 |
Correct |
308 ms |
55308 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6744 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
2 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6744 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
1 ms |
6744 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
2 ms |
6744 KB |
Output is correct |
25 |
Correct |
2 ms |
6744 KB |
Output is correct |
26 |
Correct |
3 ms |
6896 KB |
Output is correct |
27 |
Correct |
2 ms |
6744 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
1 ms |
6744 KB |
Output is correct |
30 |
Correct |
363 ms |
47884 KB |
Output is correct |
31 |
Correct |
244 ms |
56704 KB |
Output is correct |
32 |
Correct |
338 ms |
58956 KB |
Output is correct |
33 |
Correct |
281 ms |
56260 KB |
Output is correct |
34 |
Correct |
212 ms |
55888 KB |
Output is correct |
35 |
Correct |
232 ms |
56704 KB |
Output is correct |
36 |
Correct |
183 ms |
57300 KB |
Output is correct |
37 |
Correct |
427 ms |
60240 KB |
Output is correct |
38 |
Correct |
282 ms |
60440 KB |
Output is correct |
39 |
Correct |
339 ms |
56368 KB |
Output is correct |
40 |
Correct |
212 ms |
56400 KB |
Output is correct |
41 |
Correct |
160 ms |
56776 KB |
Output is correct |
42 |
Correct |
159 ms |
57288 KB |
Output is correct |
43 |
Correct |
167 ms |
56720 KB |
Output is correct |
44 |
Correct |
160 ms |
57168 KB |
Output is correct |
45 |
Correct |
169 ms |
57680 KB |
Output is correct |
46 |
Correct |
2 ms |
6744 KB |
Output is correct |
47 |
Correct |
2 ms |
6744 KB |
Output is correct |
48 |
Correct |
2 ms |
6744 KB |
Output is correct |
49 |
Correct |
2 ms |
6744 KB |
Output is correct |
50 |
Correct |
2 ms |
6744 KB |
Output is correct |
51 |
Correct |
1 ms |
6748 KB |
Output is correct |
52 |
Correct |
321 ms |
56152 KB |
Output is correct |
53 |
Correct |
224 ms |
56688 KB |
Output is correct |
54 |
Correct |
334 ms |
60452 KB |
Output is correct |
55 |
Correct |
321 ms |
56400 KB |
Output is correct |
56 |
Correct |
232 ms |
56400 KB |
Output is correct |
57 |
Correct |
217 ms |
56080 KB |
Output is correct |
58 |
Correct |
182 ms |
57072 KB |
Output is correct |
59 |
Correct |
434 ms |
59216 KB |
Output is correct |
60 |
Correct |
248 ms |
60752 KB |
Output is correct |
61 |
Correct |
353 ms |
55888 KB |
Output is correct |
62 |
Correct |
282 ms |
56636 KB |
Output is correct |
63 |
Correct |
2 ms |
6744 KB |
Output is correct |
64 |
Correct |
1 ms |
6744 KB |
Output is correct |
65 |
Correct |
2 ms |
6744 KB |
Output is correct |
66 |
Correct |
2 ms |
6744 KB |
Output is correct |
67 |
Correct |
2 ms |
6748 KB |
Output is correct |
68 |
Correct |
2 ms |
6744 KB |
Output is correct |
69 |
Correct |
1 ms |
6748 KB |
Output is correct |
70 |
Correct |
2 ms |
6744 KB |
Output is correct |
71 |
Correct |
1 ms |
6744 KB |
Output is correct |
72 |
Correct |
2 ms |
6744 KB |
Output is correct |
73 |
Correct |
2 ms |
6744 KB |
Output is correct |
74 |
Correct |
2 ms |
6944 KB |
Output is correct |
75 |
Correct |
2 ms |
6744 KB |
Output is correct |
76 |
Correct |
1 ms |
6748 KB |
Output is correct |
77 |
Correct |
2 ms |
6744 KB |
Output is correct |
78 |
Correct |
1 ms |
6744 KB |
Output is correct |
79 |
Correct |
464 ms |
49372 KB |
Output is correct |
80 |
Correct |
494 ms |
56912 KB |
Output is correct |
81 |
Correct |
417 ms |
56656 KB |
Output is correct |
82 |
Correct |
321 ms |
53544 KB |
Output is correct |
83 |
Correct |
232 ms |
53568 KB |
Output is correct |
84 |
Correct |
246 ms |
53560 KB |
Output is correct |
85 |
Correct |
189 ms |
54108 KB |
Output is correct |
86 |
Correct |
461 ms |
56144 KB |
Output is correct |
87 |
Correct |
525 ms |
57456 KB |
Output is correct |
88 |
Correct |
338 ms |
53028 KB |
Output is correct |
89 |
Correct |
337 ms |
53804 KB |
Output is correct |
90 |
Correct |
302 ms |
54608 KB |
Output is correct |
91 |
Correct |
309 ms |
55376 KB |
Output is correct |
92 |
Correct |
2 ms |
6744 KB |
Output is correct |
93 |
Correct |
1 ms |
6744 KB |
Output is correct |
94 |
Correct |
1 ms |
6744 KB |
Output is correct |
95 |
Correct |
2 ms |
6748 KB |
Output is correct |
96 |
Correct |
2 ms |
6744 KB |
Output is correct |
97 |
Correct |
2 ms |
6748 KB |
Output is correct |
98 |
Correct |
459 ms |
50772 KB |
Output is correct |
99 |
Correct |
539 ms |
56656 KB |
Output is correct |
100 |
Correct |
437 ms |
57428 KB |
Output is correct |
101 |
Correct |
328 ms |
54840 KB |
Output is correct |
102 |
Correct |
304 ms |
55120 KB |
Output is correct |
103 |
Correct |
237 ms |
54848 KB |
Output is correct |
104 |
Correct |
189 ms |
55232 KB |
Output is correct |
105 |
Correct |
433 ms |
59728 KB |
Output is correct |
106 |
Correct |
554 ms |
58192 KB |
Output is correct |
107 |
Correct |
350 ms |
55588 KB |
Output is correct |
108 |
Correct |
371 ms |
54080 KB |
Output is correct |
109 |
Correct |
297 ms |
54796 KB |
Output is correct |
110 |
Correct |
308 ms |
55308 KB |
Output is correct |
111 |
Correct |
2 ms |
6744 KB |
Output is correct |
112 |
Correct |
2 ms |
6744 KB |
Output is correct |
113 |
Correct |
2 ms |
6744 KB |
Output is correct |
114 |
Correct |
2 ms |
6744 KB |
Output is correct |
115 |
Correct |
2 ms |
6744 KB |
Output is correct |
116 |
Correct |
338 ms |
54096 KB |
Output is correct |
117 |
Correct |
417 ms |
56652 KB |
Output is correct |
118 |
Correct |
394 ms |
60392 KB |
Output is correct |
119 |
Correct |
373 ms |
56232 KB |
Output is correct |
120 |
Correct |
289 ms |
56052 KB |
Output is correct |
121 |
Correct |
307 ms |
56684 KB |
Output is correct |
122 |
Correct |
207 ms |
57012 KB |
Output is correct |
123 |
Correct |
472 ms |
59768 KB |
Output is correct |
124 |
Correct |
576 ms |
58960 KB |
Output is correct |
125 |
Correct |
358 ms |
55240 KB |
Output is correct |
126 |
Correct |
438 ms |
56656 KB |
Output is correct |
127 |
Correct |
443 ms |
56956 KB |
Output is correct |
128 |
Correct |
420 ms |
57736 KB |
Output is correct |
129 |
Correct |
420 ms |
58448 KB |
Output is correct |