#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
const int MAXN = 2e5+5;
int MOD;
vector<int>adj[MAXN];
int par[MAXN],h[MAXN],m[50][MAXN];
int mult(int a,int b)
{
return (a*1LL*b)%MOD;
}
void dfs(int v,int u){
par[v] = u;
for(int x:adj[v]){
if(x!=u)dfs(x,v);
}
}
int main()
{
owo
int n;
cin>>n>>MOD;
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(1,0);
for(int i=1;i<=n;i++){
cin>>h[i];
for(int j=0;j<=40;j++)m[j][i] = 1;
}
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==2){
int v;
cin>>v;
int ans = h[v];
int d = 0;
while(v){
ans = mult(ans,m[d][v]);
v = par[v];
d++;
if(d>40)break;
}
cout<<ans<<'\n';
}else{
int x,k,w;
cin>>x>>k>>w;
while(x!=1 && k>=0){
m[k][x] = mult(m[k][x],w);
if(k)m[k-1][x] = mult(m[k-1][x],w);
k--;
x = par[x];
}
if(k>=0){
for(int j=0;j<=k;j++)m[j][1] = mult(m[j][1],w);
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Correct |
4 ms |
5484 KB |
Output is correct |
5 |
Correct |
4 ms |
5460 KB |
Output is correct |
6 |
Correct |
4 ms |
5472 KB |
Output is correct |
7 |
Correct |
4 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5292 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
4 ms |
5332 KB |
Output is correct |
17 |
Correct |
4 ms |
5292 KB |
Output is correct |
18 |
Correct |
3 ms |
5216 KB |
Output is correct |
19 |
Correct |
3 ms |
5204 KB |
Output is correct |
20 |
Correct |
3 ms |
5156 KB |
Output is correct |
21 |
Correct |
3 ms |
5160 KB |
Output is correct |
22 |
Correct |
3 ms |
5204 KB |
Output is correct |
23 |
Correct |
3 ms |
5204 KB |
Output is correct |
24 |
Correct |
3 ms |
5160 KB |
Output is correct |
25 |
Correct |
3 ms |
5204 KB |
Output is correct |
26 |
Correct |
3 ms |
5204 KB |
Output is correct |
27 |
Correct |
4 ms |
5292 KB |
Output is correct |
28 |
Correct |
3 ms |
5292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
488 ms |
52188 KB |
Output is correct |
3 |
Correct |
293 ms |
57292 KB |
Output is correct |
4 |
Correct |
431 ms |
59816 KB |
Output is correct |
5 |
Correct |
414 ms |
57092 KB |
Output is correct |
6 |
Correct |
309 ms |
56600 KB |
Output is correct |
7 |
Correct |
309 ms |
57344 KB |
Output is correct |
8 |
Correct |
210 ms |
57888 KB |
Output is correct |
9 |
Correct |
508 ms |
60812 KB |
Output is correct |
10 |
Correct |
330 ms |
61004 KB |
Output is correct |
11 |
Correct |
502 ms |
56780 KB |
Output is correct |
12 |
Correct |
296 ms |
57164 KB |
Output is correct |
13 |
Correct |
218 ms |
57616 KB |
Output is correct |
14 |
Correct |
237 ms |
58048 KB |
Output is correct |
15 |
Correct |
224 ms |
57436 KB |
Output is correct |
16 |
Correct |
236 ms |
57900 KB |
Output is correct |
17 |
Correct |
249 ms |
58408 KB |
Output is correct |
18 |
Correct |
4 ms |
5204 KB |
Output is correct |
19 |
Correct |
4 ms |
5204 KB |
Output is correct |
20 |
Correct |
4 ms |
5204 KB |
Output is correct |
21 |
Correct |
3 ms |
5160 KB |
Output is correct |
22 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
488 ms |
52188 KB |
Output is correct |
3 |
Correct |
293 ms |
57292 KB |
Output is correct |
4 |
Correct |
431 ms |
59816 KB |
Output is correct |
5 |
Correct |
414 ms |
57092 KB |
Output is correct |
6 |
Correct |
309 ms |
56600 KB |
Output is correct |
7 |
Correct |
309 ms |
57344 KB |
Output is correct |
8 |
Correct |
210 ms |
57888 KB |
Output is correct |
9 |
Correct |
508 ms |
60812 KB |
Output is correct |
10 |
Correct |
330 ms |
61004 KB |
Output is correct |
11 |
Correct |
502 ms |
56780 KB |
Output is correct |
12 |
Correct |
296 ms |
57164 KB |
Output is correct |
13 |
Correct |
218 ms |
57616 KB |
Output is correct |
14 |
Correct |
237 ms |
58048 KB |
Output is correct |
15 |
Correct |
224 ms |
57436 KB |
Output is correct |
16 |
Correct |
236 ms |
57900 KB |
Output is correct |
17 |
Correct |
249 ms |
58408 KB |
Output is correct |
18 |
Correct |
4 ms |
5204 KB |
Output is correct |
19 |
Correct |
4 ms |
5204 KB |
Output is correct |
20 |
Correct |
4 ms |
5204 KB |
Output is correct |
21 |
Correct |
3 ms |
5160 KB |
Output is correct |
22 |
Correct |
4 ms |
5204 KB |
Output is correct |
23 |
Correct |
4 ms |
5204 KB |
Output is correct |
24 |
Correct |
502 ms |
56780 KB |
Output is correct |
25 |
Correct |
319 ms |
57220 KB |
Output is correct |
26 |
Correct |
436 ms |
61180 KB |
Output is correct |
27 |
Correct |
445 ms |
56880 KB |
Output is correct |
28 |
Correct |
319 ms |
57308 KB |
Output is correct |
29 |
Correct |
314 ms |
56812 KB |
Output is correct |
30 |
Correct |
224 ms |
57836 KB |
Output is correct |
31 |
Correct |
518 ms |
59804 KB |
Output is correct |
32 |
Correct |
329 ms |
61176 KB |
Output is correct |
33 |
Correct |
532 ms |
56828 KB |
Output is correct |
34 |
Correct |
338 ms |
57268 KB |
Output is correct |
35 |
Correct |
3 ms |
5204 KB |
Output is correct |
36 |
Correct |
3 ms |
5168 KB |
Output is correct |
37 |
Correct |
4 ms |
5204 KB |
Output is correct |
38 |
Correct |
4 ms |
5292 KB |
Output is correct |
39 |
Correct |
3 ms |
5204 KB |
Output is correct |
40 |
Correct |
4 ms |
5204 KB |
Output is correct |
41 |
Correct |
3 ms |
5204 KB |
Output is correct |
42 |
Correct |
3 ms |
5164 KB |
Output is correct |
43 |
Correct |
3 ms |
5204 KB |
Output is correct |
44 |
Correct |
3 ms |
5164 KB |
Output is correct |
45 |
Correct |
3 ms |
5204 KB |
Output is correct |
46 |
Correct |
3 ms |
5204 KB |
Output is correct |
47 |
Correct |
3 ms |
5204 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5204 KB |
Output is correct |
2 |
Correct |
565 ms |
53700 KB |
Output is correct |
3 |
Correct |
807 ms |
57680 KB |
Output is correct |
4 |
Correct |
528 ms |
57332 KB |
Output is correct |
5 |
Correct |
508 ms |
54036 KB |
Output is correct |
6 |
Correct |
347 ms |
54120 KB |
Output is correct |
7 |
Correct |
331 ms |
54280 KB |
Output is correct |
8 |
Correct |
232 ms |
54904 KB |
Output is correct |
9 |
Correct |
560 ms |
56932 KB |
Output is correct |
10 |
Correct |
729 ms |
58264 KB |
Output is correct |
11 |
Correct |
632 ms |
53644 KB |
Output is correct |
12 |
Correct |
744 ms |
54624 KB |
Output is correct |
13 |
Correct |
569 ms |
55436 KB |
Output is correct |
14 |
Correct |
554 ms |
55964 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5168 KB |
Output is correct |
18 |
Correct |
4 ms |
5160 KB |
Output is correct |
19 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
588 ms |
55324 KB |
Output is correct |
3 |
Correct |
874 ms |
57104 KB |
Output is correct |
4 |
Correct |
563 ms |
58040 KB |
Output is correct |
5 |
Correct |
512 ms |
55788 KB |
Output is correct |
6 |
Correct |
397 ms |
55752 KB |
Output is correct |
7 |
Correct |
352 ms |
55500 KB |
Output is correct |
8 |
Correct |
228 ms |
55852 KB |
Output is correct |
9 |
Correct |
561 ms |
60456 KB |
Output is correct |
10 |
Correct |
733 ms |
59136 KB |
Output is correct |
11 |
Correct |
564 ms |
56524 KB |
Output is correct |
12 |
Correct |
654 ms |
54968 KB |
Output is correct |
13 |
Correct |
503 ms |
55568 KB |
Output is correct |
14 |
Correct |
518 ms |
56108 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
3 ms |
5160 KB |
Output is correct |
17 |
Correct |
3 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
19 |
Correct |
3 ms |
5160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Correct |
4 ms |
5484 KB |
Output is correct |
5 |
Correct |
4 ms |
5460 KB |
Output is correct |
6 |
Correct |
4 ms |
5472 KB |
Output is correct |
7 |
Correct |
4 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5292 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
4 ms |
5332 KB |
Output is correct |
17 |
Correct |
4 ms |
5292 KB |
Output is correct |
18 |
Correct |
3 ms |
5216 KB |
Output is correct |
19 |
Correct |
3 ms |
5204 KB |
Output is correct |
20 |
Correct |
3 ms |
5156 KB |
Output is correct |
21 |
Correct |
3 ms |
5160 KB |
Output is correct |
22 |
Correct |
3 ms |
5204 KB |
Output is correct |
23 |
Correct |
3 ms |
5204 KB |
Output is correct |
24 |
Correct |
3 ms |
5160 KB |
Output is correct |
25 |
Correct |
3 ms |
5204 KB |
Output is correct |
26 |
Correct |
3 ms |
5204 KB |
Output is correct |
27 |
Correct |
4 ms |
5292 KB |
Output is correct |
28 |
Correct |
3 ms |
5292 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
488 ms |
52188 KB |
Output is correct |
31 |
Correct |
293 ms |
57292 KB |
Output is correct |
32 |
Correct |
431 ms |
59816 KB |
Output is correct |
33 |
Correct |
414 ms |
57092 KB |
Output is correct |
34 |
Correct |
309 ms |
56600 KB |
Output is correct |
35 |
Correct |
309 ms |
57344 KB |
Output is correct |
36 |
Correct |
210 ms |
57888 KB |
Output is correct |
37 |
Correct |
508 ms |
60812 KB |
Output is correct |
38 |
Correct |
330 ms |
61004 KB |
Output is correct |
39 |
Correct |
502 ms |
56780 KB |
Output is correct |
40 |
Correct |
296 ms |
57164 KB |
Output is correct |
41 |
Correct |
218 ms |
57616 KB |
Output is correct |
42 |
Correct |
237 ms |
58048 KB |
Output is correct |
43 |
Correct |
224 ms |
57436 KB |
Output is correct |
44 |
Correct |
236 ms |
57900 KB |
Output is correct |
45 |
Correct |
249 ms |
58408 KB |
Output is correct |
46 |
Correct |
4 ms |
5204 KB |
Output is correct |
47 |
Correct |
4 ms |
5204 KB |
Output is correct |
48 |
Correct |
4 ms |
5204 KB |
Output is correct |
49 |
Correct |
3 ms |
5160 KB |
Output is correct |
50 |
Correct |
4 ms |
5204 KB |
Output is correct |
51 |
Correct |
4 ms |
5204 KB |
Output is correct |
52 |
Correct |
502 ms |
56780 KB |
Output is correct |
53 |
Correct |
319 ms |
57220 KB |
Output is correct |
54 |
Correct |
436 ms |
61180 KB |
Output is correct |
55 |
Correct |
445 ms |
56880 KB |
Output is correct |
56 |
Correct |
319 ms |
57308 KB |
Output is correct |
57 |
Correct |
314 ms |
56812 KB |
Output is correct |
58 |
Correct |
224 ms |
57836 KB |
Output is correct |
59 |
Correct |
518 ms |
59804 KB |
Output is correct |
60 |
Correct |
329 ms |
61176 KB |
Output is correct |
61 |
Correct |
532 ms |
56828 KB |
Output is correct |
62 |
Correct |
338 ms |
57268 KB |
Output is correct |
63 |
Correct |
3 ms |
5204 KB |
Output is correct |
64 |
Correct |
3 ms |
5168 KB |
Output is correct |
65 |
Correct |
4 ms |
5204 KB |
Output is correct |
66 |
Correct |
4 ms |
5292 KB |
Output is correct |
67 |
Correct |
3 ms |
5204 KB |
Output is correct |
68 |
Correct |
4 ms |
5204 KB |
Output is correct |
69 |
Correct |
3 ms |
5204 KB |
Output is correct |
70 |
Correct |
3 ms |
5164 KB |
Output is correct |
71 |
Correct |
3 ms |
5204 KB |
Output is correct |
72 |
Correct |
3 ms |
5164 KB |
Output is correct |
73 |
Correct |
3 ms |
5204 KB |
Output is correct |
74 |
Correct |
3 ms |
5204 KB |
Output is correct |
75 |
Correct |
3 ms |
5204 KB |
Output is correct |
76 |
Correct |
3 ms |
5204 KB |
Output is correct |
77 |
Correct |
4 ms |
5204 KB |
Output is correct |
78 |
Correct |
4 ms |
5204 KB |
Output is correct |
79 |
Correct |
565 ms |
53700 KB |
Output is correct |
80 |
Correct |
807 ms |
57680 KB |
Output is correct |
81 |
Correct |
528 ms |
57332 KB |
Output is correct |
82 |
Correct |
508 ms |
54036 KB |
Output is correct |
83 |
Correct |
347 ms |
54120 KB |
Output is correct |
84 |
Correct |
331 ms |
54280 KB |
Output is correct |
85 |
Correct |
232 ms |
54904 KB |
Output is correct |
86 |
Correct |
560 ms |
56932 KB |
Output is correct |
87 |
Correct |
729 ms |
58264 KB |
Output is correct |
88 |
Correct |
632 ms |
53644 KB |
Output is correct |
89 |
Correct |
744 ms |
54624 KB |
Output is correct |
90 |
Correct |
569 ms |
55436 KB |
Output is correct |
91 |
Correct |
554 ms |
55964 KB |
Output is correct |
92 |
Correct |
4 ms |
5204 KB |
Output is correct |
93 |
Correct |
4 ms |
5204 KB |
Output is correct |
94 |
Correct |
4 ms |
5168 KB |
Output is correct |
95 |
Correct |
4 ms |
5160 KB |
Output is correct |
96 |
Correct |
4 ms |
5204 KB |
Output is correct |
97 |
Correct |
3 ms |
5204 KB |
Output is correct |
98 |
Correct |
588 ms |
55324 KB |
Output is correct |
99 |
Correct |
874 ms |
57104 KB |
Output is correct |
100 |
Correct |
563 ms |
58040 KB |
Output is correct |
101 |
Correct |
512 ms |
55788 KB |
Output is correct |
102 |
Correct |
397 ms |
55752 KB |
Output is correct |
103 |
Correct |
352 ms |
55500 KB |
Output is correct |
104 |
Correct |
228 ms |
55852 KB |
Output is correct |
105 |
Correct |
561 ms |
60456 KB |
Output is correct |
106 |
Correct |
733 ms |
59136 KB |
Output is correct |
107 |
Correct |
564 ms |
56524 KB |
Output is correct |
108 |
Correct |
654 ms |
54968 KB |
Output is correct |
109 |
Correct |
503 ms |
55568 KB |
Output is correct |
110 |
Correct |
518 ms |
56108 KB |
Output is correct |
111 |
Correct |
3 ms |
5204 KB |
Output is correct |
112 |
Correct |
3 ms |
5160 KB |
Output is correct |
113 |
Correct |
3 ms |
5204 KB |
Output is correct |
114 |
Correct |
3 ms |
5204 KB |
Output is correct |
115 |
Correct |
3 ms |
5160 KB |
Output is correct |
116 |
Correct |
597 ms |
54700 KB |
Output is correct |
117 |
Correct |
746 ms |
57540 KB |
Output is correct |
118 |
Correct |
546 ms |
61084 KB |
Output is correct |
119 |
Correct |
553 ms |
57036 KB |
Output is correct |
120 |
Correct |
397 ms |
56596 KB |
Output is correct |
121 |
Correct |
379 ms |
57468 KB |
Output is correct |
122 |
Correct |
252 ms |
57720 KB |
Output is correct |
123 |
Correct |
592 ms |
60280 KB |
Output is correct |
124 |
Correct |
803 ms |
59720 KB |
Output is correct |
125 |
Correct |
581 ms |
55884 KB |
Output is correct |
126 |
Correct |
716 ms |
57300 KB |
Output is correct |
127 |
Correct |
770 ms |
57632 KB |
Output is correct |
128 |
Correct |
533 ms |
58416 KB |
Output is correct |
129 |
Correct |
550 ms |
58952 KB |
Output is correct |