#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define eb emplace_back
#define int long long
const int maxn=2e5+9;
int n;
long long l;
vector<int>a[maxn];
long long mul[maxn][41];
int dep[maxn];
int p[maxn];
long long h[maxn];
void dfs(int u,int par){
for (auto v:a[u]){
if(v==par)continue;
p[v]=u;
dep[v]=dep[u]+1;
dfs(v,u);
}
}
void update(int x,int d,long long w){
if (x==0||d==-1)return;
update(p[x],d-1,w);
if (x==1){
for1(i,0,d)mul[x][i]=(mul[x][i]*w)%l;
}
else {
mul[x][d]=(mul[x][d]*w)%l;
if (d)mul[x][d-1]=(mul[x][d-1]*w)%l;
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
cin>>n>>l;
for1(i,1,n-1){
int u,v;
cin>>u>>v;
a[u].pb(v);
a[v].pb(u);
}
dfs(1,0);
for1(i,1,n)cin>>h[i];
for1(i,1,n){
for1(j,0,40){
mul[i][j]=1;
}
}
int q;
cin>>q;
for1(i,1,q){
int t;
cin>>t;
if (t==1){
int x,dis;
long long w;
cin>>x>>dis>>w;
update(x,dis,w);
}
else {
int x;
cin>>x;
long long nw=h[x];
int u=x;
for1(j,0,40){
nw=(nw*mul[u][j])%l;
//cout<<u<<" "<<mul[u][j]<<" "<<j<<'\n';
if (p[u]!=0)u=p[u];
else break;
}
cout<<nw<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4968 KB |
Output is correct |
4 |
Correct |
4 ms |
5460 KB |
Output is correct |
5 |
Correct |
3 ms |
5420 KB |
Output is correct |
6 |
Correct |
3 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5416 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
2 ms |
5032 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5032 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
2 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
5024 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
438 ms |
87060 KB |
Output is correct |
3 |
Correct |
304 ms |
83916 KB |
Output is correct |
4 |
Correct |
400 ms |
92548 KB |
Output is correct |
5 |
Correct |
359 ms |
85676 KB |
Output is correct |
6 |
Correct |
289 ms |
85844 KB |
Output is correct |
7 |
Correct |
269 ms |
85892 KB |
Output is correct |
8 |
Correct |
231 ms |
86072 KB |
Output is correct |
9 |
Correct |
515 ms |
98580 KB |
Output is correct |
10 |
Correct |
322 ms |
93976 KB |
Output is correct |
11 |
Correct |
448 ms |
87636 KB |
Output is correct |
12 |
Correct |
308 ms |
83948 KB |
Output is correct |
13 |
Correct |
181 ms |
84256 KB |
Output is correct |
14 |
Correct |
194 ms |
84280 KB |
Output is correct |
15 |
Correct |
184 ms |
84180 KB |
Output is correct |
16 |
Correct |
194 ms |
84184 KB |
Output is correct |
17 |
Correct |
204 ms |
84768 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
438 ms |
87060 KB |
Output is correct |
3 |
Correct |
304 ms |
83916 KB |
Output is correct |
4 |
Correct |
400 ms |
92548 KB |
Output is correct |
5 |
Correct |
359 ms |
85676 KB |
Output is correct |
6 |
Correct |
289 ms |
85844 KB |
Output is correct |
7 |
Correct |
269 ms |
85892 KB |
Output is correct |
8 |
Correct |
231 ms |
86072 KB |
Output is correct |
9 |
Correct |
515 ms |
98580 KB |
Output is correct |
10 |
Correct |
322 ms |
93976 KB |
Output is correct |
11 |
Correct |
448 ms |
87636 KB |
Output is correct |
12 |
Correct |
308 ms |
83948 KB |
Output is correct |
13 |
Correct |
181 ms |
84256 KB |
Output is correct |
14 |
Correct |
194 ms |
84280 KB |
Output is correct |
15 |
Correct |
184 ms |
84180 KB |
Output is correct |
16 |
Correct |
194 ms |
84184 KB |
Output is correct |
17 |
Correct |
204 ms |
84768 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
502 ms |
87604 KB |
Output is correct |
25 |
Correct |
286 ms |
93460 KB |
Output is correct |
26 |
Correct |
429 ms |
103792 KB |
Output is correct |
27 |
Correct |
433 ms |
93204 KB |
Output is correct |
28 |
Correct |
294 ms |
93516 KB |
Output is correct |
29 |
Correct |
260 ms |
93052 KB |
Output is correct |
30 |
Correct |
215 ms |
93824 KB |
Output is correct |
31 |
Correct |
512 ms |
100372 KB |
Output is correct |
32 |
Correct |
329 ms |
103536 KB |
Output is correct |
33 |
Correct |
462 ms |
92980 KB |
Output is correct |
34 |
Correct |
293 ms |
93444 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
2 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
2 ms |
5076 KB |
Output is correct |
39 |
Correct |
2 ms |
5032 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
3 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
2 ms |
5016 KB |
Output is correct |
44 |
Correct |
3 ms |
4948 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
2 ms |
4948 KB |
Output is correct |
47 |
Correct |
2 ms |
4948 KB |
Output is correct |
48 |
Correct |
3 ms |
5028 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
571 ms |
94680 KB |
Output is correct |
3 |
Correct |
915 ms |
98768 KB |
Output is correct |
4 |
Correct |
563 ms |
98708 KB |
Output is correct |
5 |
Correct |
532 ms |
90340 KB |
Output is correct |
6 |
Correct |
302 ms |
90336 KB |
Output is correct |
7 |
Correct |
300 ms |
90708 KB |
Output is correct |
8 |
Correct |
237 ms |
90892 KB |
Output is correct |
9 |
Correct |
587 ms |
97524 KB |
Output is correct |
10 |
Correct |
908 ms |
100500 KB |
Output is correct |
11 |
Correct |
478 ms |
89968 KB |
Output is correct |
12 |
Correct |
620 ms |
90860 KB |
Output is correct |
13 |
Correct |
421 ms |
91668 KB |
Output is correct |
14 |
Correct |
444 ms |
92616 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5020 KB |
Output is correct |
2 |
Correct |
594 ms |
93360 KB |
Output is correct |
3 |
Correct |
984 ms |
96296 KB |
Output is correct |
4 |
Correct |
565 ms |
97928 KB |
Output is correct |
5 |
Correct |
464 ms |
91864 KB |
Output is correct |
6 |
Correct |
345 ms |
92024 KB |
Output is correct |
7 |
Correct |
324 ms |
91744 KB |
Output is correct |
8 |
Correct |
229 ms |
92052 KB |
Output is correct |
9 |
Correct |
568 ms |
102748 KB |
Output is correct |
10 |
Correct |
966 ms |
101372 KB |
Output is correct |
11 |
Correct |
491 ms |
92620 KB |
Output is correct |
12 |
Correct |
620 ms |
91080 KB |
Output is correct |
13 |
Correct |
452 ms |
91852 KB |
Output is correct |
14 |
Correct |
445 ms |
92772 KB |
Output is correct |
15 |
Correct |
2 ms |
5024 KB |
Output is correct |
16 |
Correct |
3 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
5028 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4968 KB |
Output is correct |
4 |
Correct |
4 ms |
5460 KB |
Output is correct |
5 |
Correct |
3 ms |
5420 KB |
Output is correct |
6 |
Correct |
3 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5416 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
2 ms |
5032 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5032 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
2 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
5024 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
438 ms |
87060 KB |
Output is correct |
31 |
Correct |
304 ms |
83916 KB |
Output is correct |
32 |
Correct |
400 ms |
92548 KB |
Output is correct |
33 |
Correct |
359 ms |
85676 KB |
Output is correct |
34 |
Correct |
289 ms |
85844 KB |
Output is correct |
35 |
Correct |
269 ms |
85892 KB |
Output is correct |
36 |
Correct |
231 ms |
86072 KB |
Output is correct |
37 |
Correct |
515 ms |
98580 KB |
Output is correct |
38 |
Correct |
322 ms |
93976 KB |
Output is correct |
39 |
Correct |
448 ms |
87636 KB |
Output is correct |
40 |
Correct |
308 ms |
83948 KB |
Output is correct |
41 |
Correct |
181 ms |
84256 KB |
Output is correct |
42 |
Correct |
194 ms |
84280 KB |
Output is correct |
43 |
Correct |
184 ms |
84180 KB |
Output is correct |
44 |
Correct |
194 ms |
84184 KB |
Output is correct |
45 |
Correct |
204 ms |
84768 KB |
Output is correct |
46 |
Correct |
4 ms |
4948 KB |
Output is correct |
47 |
Correct |
2 ms |
4948 KB |
Output is correct |
48 |
Correct |
3 ms |
5076 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
2 ms |
4948 KB |
Output is correct |
52 |
Correct |
502 ms |
87604 KB |
Output is correct |
53 |
Correct |
286 ms |
93460 KB |
Output is correct |
54 |
Correct |
429 ms |
103792 KB |
Output is correct |
55 |
Correct |
433 ms |
93204 KB |
Output is correct |
56 |
Correct |
294 ms |
93516 KB |
Output is correct |
57 |
Correct |
260 ms |
93052 KB |
Output is correct |
58 |
Correct |
215 ms |
93824 KB |
Output is correct |
59 |
Correct |
512 ms |
100372 KB |
Output is correct |
60 |
Correct |
329 ms |
103536 KB |
Output is correct |
61 |
Correct |
462 ms |
92980 KB |
Output is correct |
62 |
Correct |
293 ms |
93444 KB |
Output is correct |
63 |
Correct |
2 ms |
4948 KB |
Output is correct |
64 |
Correct |
2 ms |
5076 KB |
Output is correct |
65 |
Correct |
3 ms |
5076 KB |
Output is correct |
66 |
Correct |
2 ms |
5076 KB |
Output is correct |
67 |
Correct |
2 ms |
5032 KB |
Output is correct |
68 |
Correct |
3 ms |
4948 KB |
Output is correct |
69 |
Correct |
3 ms |
4948 KB |
Output is correct |
70 |
Correct |
3 ms |
4948 KB |
Output is correct |
71 |
Correct |
2 ms |
5016 KB |
Output is correct |
72 |
Correct |
3 ms |
4948 KB |
Output is correct |
73 |
Correct |
3 ms |
5076 KB |
Output is correct |
74 |
Correct |
2 ms |
4948 KB |
Output is correct |
75 |
Correct |
2 ms |
4948 KB |
Output is correct |
76 |
Correct |
3 ms |
5028 KB |
Output is correct |
77 |
Correct |
3 ms |
4948 KB |
Output is correct |
78 |
Correct |
2 ms |
4948 KB |
Output is correct |
79 |
Correct |
571 ms |
94680 KB |
Output is correct |
80 |
Correct |
915 ms |
98768 KB |
Output is correct |
81 |
Correct |
563 ms |
98708 KB |
Output is correct |
82 |
Correct |
532 ms |
90340 KB |
Output is correct |
83 |
Correct |
302 ms |
90336 KB |
Output is correct |
84 |
Correct |
300 ms |
90708 KB |
Output is correct |
85 |
Correct |
237 ms |
90892 KB |
Output is correct |
86 |
Correct |
587 ms |
97524 KB |
Output is correct |
87 |
Correct |
908 ms |
100500 KB |
Output is correct |
88 |
Correct |
478 ms |
89968 KB |
Output is correct |
89 |
Correct |
620 ms |
90860 KB |
Output is correct |
90 |
Correct |
421 ms |
91668 KB |
Output is correct |
91 |
Correct |
444 ms |
92616 KB |
Output is correct |
92 |
Correct |
3 ms |
4948 KB |
Output is correct |
93 |
Correct |
2 ms |
4948 KB |
Output is correct |
94 |
Correct |
2 ms |
4948 KB |
Output is correct |
95 |
Correct |
2 ms |
4948 KB |
Output is correct |
96 |
Correct |
2 ms |
4948 KB |
Output is correct |
97 |
Correct |
2 ms |
5020 KB |
Output is correct |
98 |
Correct |
594 ms |
93360 KB |
Output is correct |
99 |
Correct |
984 ms |
96296 KB |
Output is correct |
100 |
Correct |
565 ms |
97928 KB |
Output is correct |
101 |
Correct |
464 ms |
91864 KB |
Output is correct |
102 |
Correct |
345 ms |
92024 KB |
Output is correct |
103 |
Correct |
324 ms |
91744 KB |
Output is correct |
104 |
Correct |
229 ms |
92052 KB |
Output is correct |
105 |
Correct |
568 ms |
102748 KB |
Output is correct |
106 |
Correct |
966 ms |
101372 KB |
Output is correct |
107 |
Correct |
491 ms |
92620 KB |
Output is correct |
108 |
Correct |
620 ms |
91080 KB |
Output is correct |
109 |
Correct |
452 ms |
91852 KB |
Output is correct |
110 |
Correct |
445 ms |
92772 KB |
Output is correct |
111 |
Correct |
2 ms |
5024 KB |
Output is correct |
112 |
Correct |
3 ms |
5028 KB |
Output is correct |
113 |
Correct |
3 ms |
5028 KB |
Output is correct |
114 |
Correct |
3 ms |
5076 KB |
Output is correct |
115 |
Correct |
2 ms |
4948 KB |
Output is correct |
116 |
Correct |
516 ms |
91000 KB |
Output is correct |
117 |
Correct |
718 ms |
93564 KB |
Output is correct |
118 |
Correct |
609 ms |
103656 KB |
Output is correct |
119 |
Correct |
505 ms |
93316 KB |
Output is correct |
120 |
Correct |
367 ms |
92956 KB |
Output is correct |
121 |
Correct |
401 ms |
93788 KB |
Output is correct |
122 |
Correct |
247 ms |
93772 KB |
Output is correct |
123 |
Correct |
646 ms |
101564 KB |
Output is correct |
124 |
Correct |
969 ms |
99604 KB |
Output is correct |
125 |
Correct |
493 ms |
92120 KB |
Output is correct |
126 |
Correct |
714 ms |
93472 KB |
Output is correct |
127 |
Correct |
766 ms |
93968 KB |
Output is correct |
128 |
Correct |
566 ms |
94692 KB |
Output is correct |
129 |
Correct |
598 ms |
95664 KB |
Output is correct |