#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,q,f[maxN+1][41],L,h[maxN+1],parent[maxN+1];
vector<int> adj[maxN+1];
void dfs(int u,int p)
{
parent[u]=p;
for(auto v:adj[u])
{
if(v!=p)
{
dfs(v,u);
}
}
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>L;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++)
{
cin>>h[i];
for(int j=0;j<=40;j++)
{
f[i][j]=1;
}
}
dfs(1,0);
cin>>q;
while(q--)
{
int s;
cin>>s;
if(s==1)
{
int x,d,w;
cin>>x>>d>>w;
while(d>=0&&x>0)
{
if(x==1)
{
while(d>=0)
{
f[x][d]=(1LL*f[x][d]*w)%L;
d--;
}
}
else
{
f[x][d]=(1LL*f[x][d]*w)%L;
if(d>0)
{
f[x][d-1]=(1LL*f[x][d-1]*w)%L;
}
}
x=parent[x];
d--;
}
}
else
{
int x;
cin>>x;
int ans=h[x];
int d=0;
while(d<=40&&x>0)
{
ans=(1LL*ans*f[x][d])%L;
x=parent[x];
d++;
}
cout<<ans<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5188 KB |
Output is correct |
7 |
Correct |
2 ms |
5212 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
3 ms |
5192 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5176 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
4956 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4952 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
416 ms |
56884 KB |
Output is correct |
3 |
Correct |
249 ms |
57476 KB |
Output is correct |
4 |
Correct |
345 ms |
59748 KB |
Output is correct |
5 |
Correct |
354 ms |
57172 KB |
Output is correct |
6 |
Correct |
215 ms |
56676 KB |
Output is correct |
7 |
Correct |
208 ms |
57428 KB |
Output is correct |
8 |
Correct |
173 ms |
57832 KB |
Output is correct |
9 |
Correct |
490 ms |
61008 KB |
Output is correct |
10 |
Correct |
238 ms |
61236 KB |
Output is correct |
11 |
Correct |
416 ms |
56912 KB |
Output is correct |
12 |
Correct |
231 ms |
57384 KB |
Output is correct |
13 |
Correct |
161 ms |
57560 KB |
Output is correct |
14 |
Correct |
169 ms |
58016 KB |
Output is correct |
15 |
Correct |
158 ms |
57428 KB |
Output is correct |
16 |
Correct |
163 ms |
57936 KB |
Output is correct |
17 |
Correct |
167 ms |
58448 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5068 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
416 ms |
56884 KB |
Output is correct |
3 |
Correct |
249 ms |
57476 KB |
Output is correct |
4 |
Correct |
345 ms |
59748 KB |
Output is correct |
5 |
Correct |
354 ms |
57172 KB |
Output is correct |
6 |
Correct |
215 ms |
56676 KB |
Output is correct |
7 |
Correct |
208 ms |
57428 KB |
Output is correct |
8 |
Correct |
173 ms |
57832 KB |
Output is correct |
9 |
Correct |
490 ms |
61008 KB |
Output is correct |
10 |
Correct |
238 ms |
61236 KB |
Output is correct |
11 |
Correct |
416 ms |
56912 KB |
Output is correct |
12 |
Correct |
231 ms |
57384 KB |
Output is correct |
13 |
Correct |
161 ms |
57560 KB |
Output is correct |
14 |
Correct |
169 ms |
58016 KB |
Output is correct |
15 |
Correct |
158 ms |
57428 KB |
Output is correct |
16 |
Correct |
163 ms |
57936 KB |
Output is correct |
17 |
Correct |
167 ms |
58448 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5068 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
410 ms |
56776 KB |
Output is correct |
25 |
Correct |
240 ms |
57364 KB |
Output is correct |
26 |
Correct |
367 ms |
61264 KB |
Output is correct |
27 |
Correct |
317 ms |
56916 KB |
Output is correct |
28 |
Correct |
229 ms |
57172 KB |
Output is correct |
29 |
Correct |
222 ms |
56896 KB |
Output is correct |
30 |
Correct |
172 ms |
57984 KB |
Output is correct |
31 |
Correct |
450 ms |
59728 KB |
Output is correct |
32 |
Correct |
232 ms |
61328 KB |
Output is correct |
33 |
Correct |
403 ms |
56916 KB |
Output is correct |
34 |
Correct |
226 ms |
57272 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
3 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
2 ms |
4956 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
5124 KB |
Output is correct |
46 |
Correct |
2 ms |
5188 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
5176 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
491 ms |
58144 KB |
Output is correct |
3 |
Correct |
485 ms |
57684 KB |
Output is correct |
4 |
Correct |
432 ms |
57528 KB |
Output is correct |
5 |
Correct |
361 ms |
54148 KB |
Output is correct |
6 |
Correct |
244 ms |
54356 KB |
Output is correct |
7 |
Correct |
220 ms |
54352 KB |
Output is correct |
8 |
Correct |
183 ms |
54904 KB |
Output is correct |
9 |
Correct |
479 ms |
56772 KB |
Output is correct |
10 |
Correct |
453 ms |
58276 KB |
Output is correct |
11 |
Correct |
405 ms |
53688 KB |
Output is correct |
12 |
Correct |
440 ms |
54688 KB |
Output is correct |
13 |
Correct |
285 ms |
55492 KB |
Output is correct |
14 |
Correct |
275 ms |
55964 KB |
Output is correct |
15 |
Correct |
2 ms |
5184 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
500 ms |
59264 KB |
Output is correct |
3 |
Correct |
475 ms |
57168 KB |
Output is correct |
4 |
Correct |
415 ms |
58192 KB |
Output is correct |
5 |
Correct |
346 ms |
55688 KB |
Output is correct |
6 |
Correct |
243 ms |
55892 KB |
Output is correct |
7 |
Correct |
214 ms |
55692 KB |
Output is correct |
8 |
Correct |
178 ms |
55860 KB |
Output is correct |
9 |
Correct |
466 ms |
60500 KB |
Output is correct |
10 |
Correct |
513 ms |
59016 KB |
Output is correct |
11 |
Correct |
452 ms |
56552 KB |
Output is correct |
12 |
Correct |
416 ms |
54868 KB |
Output is correct |
13 |
Correct |
294 ms |
55720 KB |
Output is correct |
14 |
Correct |
316 ms |
56144 KB |
Output is correct |
15 |
Correct |
2 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
5040 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5188 KB |
Output is correct |
7 |
Correct |
2 ms |
5212 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
3 ms |
5192 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5176 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
4956 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4952 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
416 ms |
56884 KB |
Output is correct |
31 |
Correct |
249 ms |
57476 KB |
Output is correct |
32 |
Correct |
345 ms |
59748 KB |
Output is correct |
33 |
Correct |
354 ms |
57172 KB |
Output is correct |
34 |
Correct |
215 ms |
56676 KB |
Output is correct |
35 |
Correct |
208 ms |
57428 KB |
Output is correct |
36 |
Correct |
173 ms |
57832 KB |
Output is correct |
37 |
Correct |
490 ms |
61008 KB |
Output is correct |
38 |
Correct |
238 ms |
61236 KB |
Output is correct |
39 |
Correct |
416 ms |
56912 KB |
Output is correct |
40 |
Correct |
231 ms |
57384 KB |
Output is correct |
41 |
Correct |
161 ms |
57560 KB |
Output is correct |
42 |
Correct |
169 ms |
58016 KB |
Output is correct |
43 |
Correct |
158 ms |
57428 KB |
Output is correct |
44 |
Correct |
163 ms |
57936 KB |
Output is correct |
45 |
Correct |
167 ms |
58448 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
3 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
5068 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
2 ms |
4956 KB |
Output is correct |
52 |
Correct |
410 ms |
56776 KB |
Output is correct |
53 |
Correct |
240 ms |
57364 KB |
Output is correct |
54 |
Correct |
367 ms |
61264 KB |
Output is correct |
55 |
Correct |
317 ms |
56916 KB |
Output is correct |
56 |
Correct |
229 ms |
57172 KB |
Output is correct |
57 |
Correct |
222 ms |
56896 KB |
Output is correct |
58 |
Correct |
172 ms |
57984 KB |
Output is correct |
59 |
Correct |
450 ms |
59728 KB |
Output is correct |
60 |
Correct |
232 ms |
61328 KB |
Output is correct |
61 |
Correct |
403 ms |
56916 KB |
Output is correct |
62 |
Correct |
226 ms |
57272 KB |
Output is correct |
63 |
Correct |
2 ms |
4956 KB |
Output is correct |
64 |
Correct |
2 ms |
4956 KB |
Output is correct |
65 |
Correct |
2 ms |
4956 KB |
Output is correct |
66 |
Correct |
3 ms |
4956 KB |
Output is correct |
67 |
Correct |
2 ms |
4956 KB |
Output is correct |
68 |
Correct |
3 ms |
4956 KB |
Output is correct |
69 |
Correct |
2 ms |
4956 KB |
Output is correct |
70 |
Correct |
2 ms |
4956 KB |
Output is correct |
71 |
Correct |
2 ms |
4956 KB |
Output is correct |
72 |
Correct |
2 ms |
4956 KB |
Output is correct |
73 |
Correct |
2 ms |
5124 KB |
Output is correct |
74 |
Correct |
2 ms |
5188 KB |
Output is correct |
75 |
Correct |
2 ms |
4956 KB |
Output is correct |
76 |
Correct |
2 ms |
5176 KB |
Output is correct |
77 |
Correct |
2 ms |
4956 KB |
Output is correct |
78 |
Correct |
2 ms |
4956 KB |
Output is correct |
79 |
Correct |
491 ms |
58144 KB |
Output is correct |
80 |
Correct |
485 ms |
57684 KB |
Output is correct |
81 |
Correct |
432 ms |
57528 KB |
Output is correct |
82 |
Correct |
361 ms |
54148 KB |
Output is correct |
83 |
Correct |
244 ms |
54356 KB |
Output is correct |
84 |
Correct |
220 ms |
54352 KB |
Output is correct |
85 |
Correct |
183 ms |
54904 KB |
Output is correct |
86 |
Correct |
479 ms |
56772 KB |
Output is correct |
87 |
Correct |
453 ms |
58276 KB |
Output is correct |
88 |
Correct |
405 ms |
53688 KB |
Output is correct |
89 |
Correct |
440 ms |
54688 KB |
Output is correct |
90 |
Correct |
285 ms |
55492 KB |
Output is correct |
91 |
Correct |
275 ms |
55964 KB |
Output is correct |
92 |
Correct |
2 ms |
5184 KB |
Output is correct |
93 |
Correct |
2 ms |
4956 KB |
Output is correct |
94 |
Correct |
1 ms |
4956 KB |
Output is correct |
95 |
Correct |
2 ms |
4956 KB |
Output is correct |
96 |
Correct |
2 ms |
5168 KB |
Output is correct |
97 |
Correct |
2 ms |
4956 KB |
Output is correct |
98 |
Correct |
500 ms |
59264 KB |
Output is correct |
99 |
Correct |
475 ms |
57168 KB |
Output is correct |
100 |
Correct |
415 ms |
58192 KB |
Output is correct |
101 |
Correct |
346 ms |
55688 KB |
Output is correct |
102 |
Correct |
243 ms |
55892 KB |
Output is correct |
103 |
Correct |
214 ms |
55692 KB |
Output is correct |
104 |
Correct |
178 ms |
55860 KB |
Output is correct |
105 |
Correct |
466 ms |
60500 KB |
Output is correct |
106 |
Correct |
513 ms |
59016 KB |
Output is correct |
107 |
Correct |
452 ms |
56552 KB |
Output is correct |
108 |
Correct |
416 ms |
54868 KB |
Output is correct |
109 |
Correct |
294 ms |
55720 KB |
Output is correct |
110 |
Correct |
316 ms |
56144 KB |
Output is correct |
111 |
Correct |
2 ms |
4952 KB |
Output is correct |
112 |
Correct |
2 ms |
4956 KB |
Output is correct |
113 |
Correct |
2 ms |
4956 KB |
Output is correct |
114 |
Correct |
2 ms |
5040 KB |
Output is correct |
115 |
Correct |
2 ms |
4956 KB |
Output is correct |
116 |
Correct |
434 ms |
54756 KB |
Output is correct |
117 |
Correct |
428 ms |
57508 KB |
Output is correct |
118 |
Correct |
406 ms |
61008 KB |
Output is correct |
119 |
Correct |
368 ms |
57004 KB |
Output is correct |
120 |
Correct |
232 ms |
56796 KB |
Output is correct |
121 |
Correct |
225 ms |
57596 KB |
Output is correct |
122 |
Correct |
189 ms |
57728 KB |
Output is correct |
123 |
Correct |
454 ms |
60144 KB |
Output is correct |
124 |
Correct |
503 ms |
59748 KB |
Output is correct |
125 |
Correct |
437 ms |
55892 KB |
Output is correct |
126 |
Correct |
454 ms |
57308 KB |
Output is correct |
127 |
Correct |
457 ms |
57888 KB |
Output is correct |
128 |
Correct |
289 ms |
58448 KB |
Output is correct |
129 |
Correct |
319 ms |
58996 KB |
Output is correct |