#include <bits/stdc++.h>
#define pb push_back
using namespace std;
long long p[201000],a[200001];
long long d[201000][41];
vector<long long> adj[200001];
void dfs(long long x, long long par) {
for (auto k :adj[x]){
if (k == par) continue;
p[k] = x;
dfs(k , x);
}
}
int main(){
long long n, md;
cin>>n>>md;
for (int i=1; i<n; i++) {
long long x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(1 , 1);
p[1]=n+1;
for(int i=n+2; i<=n+40; i++){
p[i-1] = i;
}
for (int i=1; i<=n; i++) {
cin>>a[i];
}
for (int i=1; i<=n+40; i++) {
for (int j=0; j<=40; j++) {
d[i][j] = 1;
}
}
long long q;
cin>>q;
for (int i = 1; i <= q; i++) {
long long temp; cin>>temp;
if (temp == 2) {
long long x , pas = 1;
cin>>x;
pas = a[x];
long long j = 0;
while (j <= 40) {
pas *= d[x][j];
pas %= md;
x=p[x];
j++;
}
cout<<pas<<endl;
}else {
long long x, r, w;
cin>>x>>r>>w;
long long j = r;
while (j > 0) {
d[x][j]*=w;
d[x][j]%=md;
d[x][j - 1]*=w;
d[x][j - 1]%=md;
//cput<<" "<<pas<<" br"<<endl;
x=p[x];
j--;
}
d[x][j] *= w;
d[x][j] %= md;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5072 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
6 ms |
5332 KB |
Output is correct |
5 |
Correct |
6 ms |
5332 KB |
Output is correct |
6 |
Correct |
6 ms |
5348 KB |
Output is correct |
7 |
Correct |
5 ms |
5332 KB |
Output is correct |
8 |
Correct |
5 ms |
5332 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
5 ms |
4948 KB |
Output is correct |
12 |
Correct |
5 ms |
4948 KB |
Output is correct |
13 |
Correct |
4 ms |
5016 KB |
Output is correct |
14 |
Correct |
5 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
4948 KB |
Output is correct |
16 |
Correct |
5 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
5016 KB |
Output is correct |
24 |
Correct |
5 ms |
5076 KB |
Output is correct |
25 |
Correct |
5 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
4948 KB |
Output is correct |
27 |
Correct |
5 ms |
4948 KB |
Output is correct |
28 |
Correct |
5 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1432 ms |
91400 KB |
Output is correct |
3 |
Correct |
862 ms |
92004 KB |
Output is correct |
4 |
Correct |
1123 ms |
94192 KB |
Output is correct |
5 |
Correct |
1111 ms |
91740 KB |
Output is correct |
6 |
Correct |
938 ms |
91228 KB |
Output is correct |
7 |
Correct |
917 ms |
92092 KB |
Output is correct |
8 |
Correct |
909 ms |
92332 KB |
Output is correct |
9 |
Correct |
1507 ms |
95568 KB |
Output is correct |
10 |
Correct |
870 ms |
95800 KB |
Output is correct |
11 |
Correct |
1378 ms |
91040 KB |
Output is correct |
12 |
Correct |
812 ms |
91920 KB |
Output is correct |
13 |
Correct |
654 ms |
91944 KB |
Output is correct |
14 |
Correct |
686 ms |
92464 KB |
Output is correct |
15 |
Correct |
685 ms |
91720 KB |
Output is correct |
16 |
Correct |
688 ms |
92432 KB |
Output is correct |
17 |
Correct |
684 ms |
92228 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5020 KB |
Output is correct |
22 |
Correct |
5 ms |
5132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1432 ms |
91400 KB |
Output is correct |
3 |
Correct |
862 ms |
92004 KB |
Output is correct |
4 |
Correct |
1123 ms |
94192 KB |
Output is correct |
5 |
Correct |
1111 ms |
91740 KB |
Output is correct |
6 |
Correct |
938 ms |
91228 KB |
Output is correct |
7 |
Correct |
917 ms |
92092 KB |
Output is correct |
8 |
Correct |
909 ms |
92332 KB |
Output is correct |
9 |
Correct |
1507 ms |
95568 KB |
Output is correct |
10 |
Correct |
870 ms |
95800 KB |
Output is correct |
11 |
Correct |
1378 ms |
91040 KB |
Output is correct |
12 |
Correct |
812 ms |
91920 KB |
Output is correct |
13 |
Correct |
654 ms |
91944 KB |
Output is correct |
14 |
Correct |
686 ms |
92464 KB |
Output is correct |
15 |
Correct |
685 ms |
91720 KB |
Output is correct |
16 |
Correct |
688 ms |
92432 KB |
Output is correct |
17 |
Correct |
684 ms |
92228 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5020 KB |
Output is correct |
22 |
Correct |
5 ms |
5132 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
1405 ms |
91412 KB |
Output is correct |
25 |
Correct |
796 ms |
92040 KB |
Output is correct |
26 |
Correct |
1139 ms |
95820 KB |
Output is correct |
27 |
Correct |
1016 ms |
91684 KB |
Output is correct |
28 |
Correct |
907 ms |
91932 KB |
Output is correct |
29 |
Correct |
877 ms |
91680 KB |
Output is correct |
30 |
Correct |
845 ms |
92408 KB |
Output is correct |
31 |
Correct |
1338 ms |
94112 KB |
Output is correct |
32 |
Correct |
768 ms |
95772 KB |
Output is correct |
33 |
Correct |
1264 ms |
91392 KB |
Output is correct |
34 |
Correct |
784 ms |
91888 KB |
Output is correct |
35 |
Correct |
4 ms |
4948 KB |
Output is correct |
36 |
Correct |
4 ms |
5012 KB |
Output is correct |
37 |
Correct |
4 ms |
4948 KB |
Output is correct |
38 |
Correct |
4 ms |
5012 KB |
Output is correct |
39 |
Correct |
4 ms |
4948 KB |
Output is correct |
40 |
Correct |
4 ms |
4948 KB |
Output is correct |
41 |
Correct |
4 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
4 ms |
5008 KB |
Output is correct |
44 |
Correct |
4 ms |
5012 KB |
Output is correct |
45 |
Correct |
4 ms |
5008 KB |
Output is correct |
46 |
Correct |
4 ms |
4948 KB |
Output is correct |
47 |
Correct |
4 ms |
4948 KB |
Output is correct |
48 |
Correct |
4 ms |
4948 KB |
Output is correct |
49 |
Correct |
5 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1341 ms |
92656 KB |
Output is correct |
3 |
Correct |
1078 ms |
92312 KB |
Output is correct |
4 |
Correct |
1119 ms |
92024 KB |
Output is correct |
5 |
Correct |
1090 ms |
88948 KB |
Output is correct |
6 |
Correct |
917 ms |
88896 KB |
Output is correct |
7 |
Correct |
883 ms |
89164 KB |
Output is correct |
8 |
Correct |
845 ms |
89400 KB |
Output is correct |
9 |
Correct |
1367 ms |
91360 KB |
Output is correct |
10 |
Correct |
1102 ms |
92744 KB |
Output is correct |
11 |
Correct |
1301 ms |
88500 KB |
Output is correct |
12 |
Correct |
1020 ms |
89276 KB |
Output is correct |
13 |
Correct |
759 ms |
90188 KB |
Output is correct |
14 |
Correct |
806 ms |
90952 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5036 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1435 ms |
93628 KB |
Output is correct |
3 |
Correct |
1156 ms |
91276 KB |
Output is correct |
4 |
Correct |
1233 ms |
92364 KB |
Output is correct |
5 |
Correct |
1142 ms |
90340 KB |
Output is correct |
6 |
Correct |
949 ms |
90748 KB |
Output is correct |
7 |
Correct |
936 ms |
90264 KB |
Output is correct |
8 |
Correct |
853 ms |
90280 KB |
Output is correct |
9 |
Correct |
1356 ms |
95148 KB |
Output is correct |
10 |
Correct |
1114 ms |
93468 KB |
Output is correct |
11 |
Correct |
1359 ms |
91068 KB |
Output is correct |
12 |
Correct |
1020 ms |
89532 KB |
Output is correct |
13 |
Correct |
769 ms |
90328 KB |
Output is correct |
14 |
Correct |
775 ms |
91212 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5008 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5072 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
6 ms |
5332 KB |
Output is correct |
5 |
Correct |
6 ms |
5332 KB |
Output is correct |
6 |
Correct |
6 ms |
5348 KB |
Output is correct |
7 |
Correct |
5 ms |
5332 KB |
Output is correct |
8 |
Correct |
5 ms |
5332 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
5 ms |
4948 KB |
Output is correct |
12 |
Correct |
5 ms |
4948 KB |
Output is correct |
13 |
Correct |
4 ms |
5016 KB |
Output is correct |
14 |
Correct |
5 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
4948 KB |
Output is correct |
16 |
Correct |
5 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
5016 KB |
Output is correct |
24 |
Correct |
5 ms |
5076 KB |
Output is correct |
25 |
Correct |
5 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
4948 KB |
Output is correct |
27 |
Correct |
5 ms |
4948 KB |
Output is correct |
28 |
Correct |
5 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
1432 ms |
91400 KB |
Output is correct |
31 |
Correct |
862 ms |
92004 KB |
Output is correct |
32 |
Correct |
1123 ms |
94192 KB |
Output is correct |
33 |
Correct |
1111 ms |
91740 KB |
Output is correct |
34 |
Correct |
938 ms |
91228 KB |
Output is correct |
35 |
Correct |
917 ms |
92092 KB |
Output is correct |
36 |
Correct |
909 ms |
92332 KB |
Output is correct |
37 |
Correct |
1507 ms |
95568 KB |
Output is correct |
38 |
Correct |
870 ms |
95800 KB |
Output is correct |
39 |
Correct |
1378 ms |
91040 KB |
Output is correct |
40 |
Correct |
812 ms |
91920 KB |
Output is correct |
41 |
Correct |
654 ms |
91944 KB |
Output is correct |
42 |
Correct |
686 ms |
92464 KB |
Output is correct |
43 |
Correct |
685 ms |
91720 KB |
Output is correct |
44 |
Correct |
688 ms |
92432 KB |
Output is correct |
45 |
Correct |
684 ms |
92228 KB |
Output is correct |
46 |
Correct |
4 ms |
4948 KB |
Output is correct |
47 |
Correct |
4 ms |
4948 KB |
Output is correct |
48 |
Correct |
4 ms |
4948 KB |
Output is correct |
49 |
Correct |
4 ms |
5020 KB |
Output is correct |
50 |
Correct |
5 ms |
5132 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
1405 ms |
91412 KB |
Output is correct |
53 |
Correct |
796 ms |
92040 KB |
Output is correct |
54 |
Correct |
1139 ms |
95820 KB |
Output is correct |
55 |
Correct |
1016 ms |
91684 KB |
Output is correct |
56 |
Correct |
907 ms |
91932 KB |
Output is correct |
57 |
Correct |
877 ms |
91680 KB |
Output is correct |
58 |
Correct |
845 ms |
92408 KB |
Output is correct |
59 |
Correct |
1338 ms |
94112 KB |
Output is correct |
60 |
Correct |
768 ms |
95772 KB |
Output is correct |
61 |
Correct |
1264 ms |
91392 KB |
Output is correct |
62 |
Correct |
784 ms |
91888 KB |
Output is correct |
63 |
Correct |
4 ms |
4948 KB |
Output is correct |
64 |
Correct |
4 ms |
5012 KB |
Output is correct |
65 |
Correct |
4 ms |
4948 KB |
Output is correct |
66 |
Correct |
4 ms |
5012 KB |
Output is correct |
67 |
Correct |
4 ms |
4948 KB |
Output is correct |
68 |
Correct |
4 ms |
4948 KB |
Output is correct |
69 |
Correct |
4 ms |
4948 KB |
Output is correct |
70 |
Correct |
3 ms |
4948 KB |
Output is correct |
71 |
Correct |
4 ms |
5008 KB |
Output is correct |
72 |
Correct |
4 ms |
5012 KB |
Output is correct |
73 |
Correct |
4 ms |
5008 KB |
Output is correct |
74 |
Correct |
4 ms |
4948 KB |
Output is correct |
75 |
Correct |
4 ms |
4948 KB |
Output is correct |
76 |
Correct |
4 ms |
4948 KB |
Output is correct |
77 |
Correct |
5 ms |
4948 KB |
Output is correct |
78 |
Correct |
3 ms |
4948 KB |
Output is correct |
79 |
Correct |
1341 ms |
92656 KB |
Output is correct |
80 |
Correct |
1078 ms |
92312 KB |
Output is correct |
81 |
Correct |
1119 ms |
92024 KB |
Output is correct |
82 |
Correct |
1090 ms |
88948 KB |
Output is correct |
83 |
Correct |
917 ms |
88896 KB |
Output is correct |
84 |
Correct |
883 ms |
89164 KB |
Output is correct |
85 |
Correct |
845 ms |
89400 KB |
Output is correct |
86 |
Correct |
1367 ms |
91360 KB |
Output is correct |
87 |
Correct |
1102 ms |
92744 KB |
Output is correct |
88 |
Correct |
1301 ms |
88500 KB |
Output is correct |
89 |
Correct |
1020 ms |
89276 KB |
Output is correct |
90 |
Correct |
759 ms |
90188 KB |
Output is correct |
91 |
Correct |
806 ms |
90952 KB |
Output is correct |
92 |
Correct |
4 ms |
4948 KB |
Output is correct |
93 |
Correct |
4 ms |
4948 KB |
Output is correct |
94 |
Correct |
4 ms |
4948 KB |
Output is correct |
95 |
Correct |
4 ms |
5036 KB |
Output is correct |
96 |
Correct |
4 ms |
4948 KB |
Output is correct |
97 |
Correct |
3 ms |
4948 KB |
Output is correct |
98 |
Correct |
1435 ms |
93628 KB |
Output is correct |
99 |
Correct |
1156 ms |
91276 KB |
Output is correct |
100 |
Correct |
1233 ms |
92364 KB |
Output is correct |
101 |
Correct |
1142 ms |
90340 KB |
Output is correct |
102 |
Correct |
949 ms |
90748 KB |
Output is correct |
103 |
Correct |
936 ms |
90264 KB |
Output is correct |
104 |
Correct |
853 ms |
90280 KB |
Output is correct |
105 |
Correct |
1356 ms |
95148 KB |
Output is correct |
106 |
Correct |
1114 ms |
93468 KB |
Output is correct |
107 |
Correct |
1359 ms |
91068 KB |
Output is correct |
108 |
Correct |
1020 ms |
89532 KB |
Output is correct |
109 |
Correct |
769 ms |
90328 KB |
Output is correct |
110 |
Correct |
775 ms |
91212 KB |
Output is correct |
111 |
Correct |
4 ms |
4948 KB |
Output is correct |
112 |
Correct |
4 ms |
4948 KB |
Output is correct |
113 |
Correct |
4 ms |
4948 KB |
Output is correct |
114 |
Correct |
4 ms |
5008 KB |
Output is correct |
115 |
Correct |
3 ms |
4948 KB |
Output is correct |
116 |
Correct |
1308 ms |
89516 KB |
Output is correct |
117 |
Correct |
1096 ms |
92012 KB |
Output is correct |
118 |
Correct |
1205 ms |
95716 KB |
Output is correct |
119 |
Correct |
1176 ms |
91656 KB |
Output is correct |
120 |
Correct |
1002 ms |
91392 KB |
Output is correct |
121 |
Correct |
1031 ms |
92332 KB |
Output is correct |
122 |
Correct |
942 ms |
92216 KB |
Output is correct |
123 |
Correct |
1367 ms |
94604 KB |
Output is correct |
124 |
Correct |
1184 ms |
94068 KB |
Output is correct |
125 |
Correct |
1342 ms |
90636 KB |
Output is correct |
126 |
Correct |
1129 ms |
91920 KB |
Output is correct |
127 |
Correct |
1128 ms |
92580 KB |
Output is correct |
128 |
Correct |
942 ms |
93040 KB |
Output is correct |
129 |
Correct |
959 ms |
94184 KB |
Output is correct |