//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
int mod;
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 2e5+10;
int fa[maxn];
vector <int> edge[maxn];
int tag[maxn][44];
int n;
int w[maxn];
void dfs(int u,int lst) {
fa[u] = lst;
rep(i,0,41) tag[u][i] = 1;
for (int v:edge[u]) {
if (v==lst) continue;
dfs(v,u);
}
}
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>mod;
rep(i,1,n) {
int u,v;cin>>u>>v;
edge[u].pb(v);
edge[v].pb(u);
}
dfs(1,-1);
rep(i,1,n+1) cin>>w[i];
int _;cin>>_;
while (_--) {
int x,y;
cin>>x>>y;
if (x==1) {
int d,z;cin>>d>>z;
int cur = y;
while (d>=0 and cur!=-1) {
tag[cur][d] = 1ll*tag[cur][d]*z%mod;
if (d!=0) tag[cur][d-1] = 1ll*tag[cur][d-1]*z%mod;
d--;
cur = fa[cur];
}
d--;
while (d>=0) tag[1][d] = 1ll*tag[1][d]*z%mod,d--;
}
else {
int ret = w[y];
int cur = y;int dis = 0;
while (cur!=-1 and dis<=40) {
ret = 1ll*ret*tag[cur][dis]%mod;
dis++;
cur = fa[cur];
}
cout<<ret<<"\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5204 KB |
Output is correct |
5 |
Correct |
4 ms |
5204 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5292 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5032 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5032 KB |
Output is correct |
14 |
Correct |
3 ms |
5036 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5036 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 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 |
5032 KB |
Output is correct |
24 |
Correct |
3 ms |
5024 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
5032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
528 ms |
59120 KB |
Output is correct |
3 |
Correct |
384 ms |
59772 KB |
Output is correct |
4 |
Correct |
494 ms |
65224 KB |
Output is correct |
5 |
Correct |
481 ms |
59440 KB |
Output is correct |
6 |
Correct |
355 ms |
59008 KB |
Output is correct |
7 |
Correct |
355 ms |
59656 KB |
Output is correct |
8 |
Correct |
277 ms |
60136 KB |
Output is correct |
9 |
Correct |
606 ms |
67984 KB |
Output is correct |
10 |
Correct |
415 ms |
67824 KB |
Output is correct |
11 |
Correct |
553 ms |
59268 KB |
Output is correct |
12 |
Correct |
360 ms |
59672 KB |
Output is correct |
13 |
Correct |
276 ms |
59916 KB |
Output is correct |
14 |
Correct |
250 ms |
60348 KB |
Output is correct |
15 |
Correct |
264 ms |
59748 KB |
Output is correct |
16 |
Correct |
307 ms |
60216 KB |
Output is correct |
17 |
Correct |
277 ms |
60796 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5032 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
528 ms |
59120 KB |
Output is correct |
3 |
Correct |
384 ms |
59772 KB |
Output is correct |
4 |
Correct |
494 ms |
65224 KB |
Output is correct |
5 |
Correct |
481 ms |
59440 KB |
Output is correct |
6 |
Correct |
355 ms |
59008 KB |
Output is correct |
7 |
Correct |
355 ms |
59656 KB |
Output is correct |
8 |
Correct |
277 ms |
60136 KB |
Output is correct |
9 |
Correct |
606 ms |
67984 KB |
Output is correct |
10 |
Correct |
415 ms |
67824 KB |
Output is correct |
11 |
Correct |
553 ms |
59268 KB |
Output is correct |
12 |
Correct |
360 ms |
59672 KB |
Output is correct |
13 |
Correct |
276 ms |
59916 KB |
Output is correct |
14 |
Correct |
250 ms |
60348 KB |
Output is correct |
15 |
Correct |
264 ms |
59748 KB |
Output is correct |
16 |
Correct |
307 ms |
60216 KB |
Output is correct |
17 |
Correct |
277 ms |
60796 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5032 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4920 KB |
Output is correct |
24 |
Correct |
524 ms |
59204 KB |
Output is correct |
25 |
Correct |
360 ms |
59716 KB |
Output is correct |
26 |
Correct |
464 ms |
68012 KB |
Output is correct |
27 |
Correct |
422 ms |
59468 KB |
Output is correct |
28 |
Correct |
359 ms |
59524 KB |
Output is correct |
29 |
Correct |
321 ms |
59264 KB |
Output is correct |
30 |
Correct |
250 ms |
60184 KB |
Output is correct |
31 |
Correct |
589 ms |
65504 KB |
Output is correct |
32 |
Correct |
386 ms |
67872 KB |
Output is correct |
33 |
Correct |
470 ms |
59060 KB |
Output is correct |
34 |
Correct |
351 ms |
59596 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
5028 KB |
Output is correct |
41 |
Correct |
3 ms |
5028 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
3 ms |
4948 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5024 KB |
Output is correct |
46 |
Correct |
3 ms |
5024 KB |
Output is correct |
47 |
Correct |
3 ms |
4948 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
575 ms |
65096 KB |
Output is correct |
3 |
Correct |
662 ms |
63668 KB |
Output is correct |
4 |
Correct |
538 ms |
63436 KB |
Output is correct |
5 |
Correct |
470 ms |
56576 KB |
Output is correct |
6 |
Correct |
347 ms |
56488 KB |
Output is correct |
7 |
Correct |
361 ms |
56796 KB |
Output is correct |
8 |
Correct |
271 ms |
57144 KB |
Output is correct |
9 |
Correct |
611 ms |
62400 KB |
Output is correct |
10 |
Correct |
702 ms |
64884 KB |
Output is correct |
11 |
Correct |
512 ms |
56008 KB |
Output is correct |
12 |
Correct |
579 ms |
56996 KB |
Output is correct |
13 |
Correct |
436 ms |
57800 KB |
Output is correct |
14 |
Correct |
429 ms |
58364 KB |
Output is correct |
15 |
Correct |
3 ms |
5032 KB |
Output is correct |
16 |
Correct |
5 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
735 ms |
64712 KB |
Output is correct |
3 |
Correct |
727 ms |
61876 KB |
Output is correct |
4 |
Correct |
561 ms |
63264 KB |
Output is correct |
5 |
Correct |
505 ms |
57992 KB |
Output is correct |
6 |
Correct |
429 ms |
58136 KB |
Output is correct |
7 |
Correct |
448 ms |
57880 KB |
Output is correct |
8 |
Correct |
309 ms |
58192 KB |
Output is correct |
9 |
Correct |
662 ms |
67148 KB |
Output is correct |
10 |
Correct |
710 ms |
65712 KB |
Output is correct |
11 |
Correct |
563 ms |
58716 KB |
Output is correct |
12 |
Correct |
643 ms |
57268 KB |
Output is correct |
13 |
Correct |
420 ms |
57944 KB |
Output is correct |
14 |
Correct |
421 ms |
58444 KB |
Output is correct |
15 |
Correct |
3 ms |
5032 KB |
Output is correct |
16 |
Correct |
4 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5204 KB |
Output is correct |
5 |
Correct |
4 ms |
5204 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5292 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5032 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5032 KB |
Output is correct |
14 |
Correct |
3 ms |
5036 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5036 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 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 |
5032 KB |
Output is correct |
24 |
Correct |
3 ms |
5024 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
5032 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
528 ms |
59120 KB |
Output is correct |
31 |
Correct |
384 ms |
59772 KB |
Output is correct |
32 |
Correct |
494 ms |
65224 KB |
Output is correct |
33 |
Correct |
481 ms |
59440 KB |
Output is correct |
34 |
Correct |
355 ms |
59008 KB |
Output is correct |
35 |
Correct |
355 ms |
59656 KB |
Output is correct |
36 |
Correct |
277 ms |
60136 KB |
Output is correct |
37 |
Correct |
606 ms |
67984 KB |
Output is correct |
38 |
Correct |
415 ms |
67824 KB |
Output is correct |
39 |
Correct |
553 ms |
59268 KB |
Output is correct |
40 |
Correct |
360 ms |
59672 KB |
Output is correct |
41 |
Correct |
276 ms |
59916 KB |
Output is correct |
42 |
Correct |
250 ms |
60348 KB |
Output is correct |
43 |
Correct |
264 ms |
59748 KB |
Output is correct |
44 |
Correct |
307 ms |
60216 KB |
Output is correct |
45 |
Correct |
277 ms |
60796 KB |
Output is correct |
46 |
Correct |
3 ms |
4948 KB |
Output is correct |
47 |
Correct |
4 ms |
5032 KB |
Output is correct |
48 |
Correct |
4 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
3 ms |
4920 KB |
Output is correct |
52 |
Correct |
524 ms |
59204 KB |
Output is correct |
53 |
Correct |
360 ms |
59716 KB |
Output is correct |
54 |
Correct |
464 ms |
68012 KB |
Output is correct |
55 |
Correct |
422 ms |
59468 KB |
Output is correct |
56 |
Correct |
359 ms |
59524 KB |
Output is correct |
57 |
Correct |
321 ms |
59264 KB |
Output is correct |
58 |
Correct |
250 ms |
60184 KB |
Output is correct |
59 |
Correct |
589 ms |
65504 KB |
Output is correct |
60 |
Correct |
386 ms |
67872 KB |
Output is correct |
61 |
Correct |
470 ms |
59060 KB |
Output is correct |
62 |
Correct |
351 ms |
59596 KB |
Output is correct |
63 |
Correct |
3 ms |
4948 KB |
Output is correct |
64 |
Correct |
3 ms |
4948 KB |
Output is correct |
65 |
Correct |
3 ms |
4948 KB |
Output is correct |
66 |
Correct |
3 ms |
4948 KB |
Output is correct |
67 |
Correct |
3 ms |
4948 KB |
Output is correct |
68 |
Correct |
3 ms |
5028 KB |
Output is correct |
69 |
Correct |
3 ms |
5028 KB |
Output is correct |
70 |
Correct |
3 ms |
4948 KB |
Output is correct |
71 |
Correct |
3 ms |
4948 KB |
Output is correct |
72 |
Correct |
3 ms |
5076 KB |
Output is correct |
73 |
Correct |
3 ms |
5024 KB |
Output is correct |
74 |
Correct |
3 ms |
5024 KB |
Output is correct |
75 |
Correct |
3 ms |
4948 KB |
Output is correct |
76 |
Correct |
3 ms |
4948 KB |
Output is correct |
77 |
Correct |
3 ms |
4948 KB |
Output is correct |
78 |
Correct |
2 ms |
4948 KB |
Output is correct |
79 |
Correct |
575 ms |
65096 KB |
Output is correct |
80 |
Correct |
662 ms |
63668 KB |
Output is correct |
81 |
Correct |
538 ms |
63436 KB |
Output is correct |
82 |
Correct |
470 ms |
56576 KB |
Output is correct |
83 |
Correct |
347 ms |
56488 KB |
Output is correct |
84 |
Correct |
361 ms |
56796 KB |
Output is correct |
85 |
Correct |
271 ms |
57144 KB |
Output is correct |
86 |
Correct |
611 ms |
62400 KB |
Output is correct |
87 |
Correct |
702 ms |
64884 KB |
Output is correct |
88 |
Correct |
512 ms |
56008 KB |
Output is correct |
89 |
Correct |
579 ms |
56996 KB |
Output is correct |
90 |
Correct |
436 ms |
57800 KB |
Output is correct |
91 |
Correct |
429 ms |
58364 KB |
Output is correct |
92 |
Correct |
3 ms |
5032 KB |
Output is correct |
93 |
Correct |
5 ms |
5028 KB |
Output is correct |
94 |
Correct |
3 ms |
4948 KB |
Output is correct |
95 |
Correct |
3 ms |
4948 KB |
Output is correct |
96 |
Correct |
3 ms |
4948 KB |
Output is correct |
97 |
Correct |
4 ms |
4948 KB |
Output is correct |
98 |
Correct |
735 ms |
64712 KB |
Output is correct |
99 |
Correct |
727 ms |
61876 KB |
Output is correct |
100 |
Correct |
561 ms |
63264 KB |
Output is correct |
101 |
Correct |
505 ms |
57992 KB |
Output is correct |
102 |
Correct |
429 ms |
58136 KB |
Output is correct |
103 |
Correct |
448 ms |
57880 KB |
Output is correct |
104 |
Correct |
309 ms |
58192 KB |
Output is correct |
105 |
Correct |
662 ms |
67148 KB |
Output is correct |
106 |
Correct |
710 ms |
65712 KB |
Output is correct |
107 |
Correct |
563 ms |
58716 KB |
Output is correct |
108 |
Correct |
643 ms |
57268 KB |
Output is correct |
109 |
Correct |
420 ms |
57944 KB |
Output is correct |
110 |
Correct |
421 ms |
58444 KB |
Output is correct |
111 |
Correct |
3 ms |
5032 KB |
Output is correct |
112 |
Correct |
4 ms |
5028 KB |
Output is correct |
113 |
Correct |
3 ms |
4948 KB |
Output is correct |
114 |
Correct |
3 ms |
4948 KB |
Output is correct |
115 |
Correct |
3 ms |
4948 KB |
Output is correct |
116 |
Correct |
562 ms |
57176 KB |
Output is correct |
117 |
Correct |
638 ms |
59756 KB |
Output is correct |
118 |
Correct |
590 ms |
67896 KB |
Output is correct |
119 |
Correct |
504 ms |
59408 KB |
Output is correct |
120 |
Correct |
391 ms |
58968 KB |
Output is correct |
121 |
Correct |
405 ms |
59852 KB |
Output is correct |
122 |
Correct |
294 ms |
60140 KB |
Output is correct |
123 |
Correct |
580 ms |
66388 KB |
Output is correct |
124 |
Correct |
697 ms |
64924 KB |
Output is correct |
125 |
Correct |
502 ms |
58296 KB |
Output is correct |
126 |
Correct |
614 ms |
59692 KB |
Output is correct |
127 |
Correct |
610 ms |
60176 KB |
Output is correct |
128 |
Correct |
522 ms |
60824 KB |
Output is correct |
129 |
Correct |
528 ms |
61260 KB |
Output is correct |