#include <bits/stdc++.h>
using namespace std;/*
<<<<It's never too late for a new beginning in your life>>>>
Today is hard
tomorrow will worse
but the day after tomorrow will be the sunshine..
HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD............
Never give up */
///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///* */
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vii;
const long long N = 2e5+50, inf = 1e18, mod = 1e9+7;
vi g[N];
int pre[N];
void dfs(int i, int pr){
pre[i] = pr;
for(auto to:g[i])if(to!=pr)dfs(to, i);
}
void solve(){
int n, m;
cin >> n >> m;
for(int i = 0; i < n-1; i++){
int u, v;
cin >> u >> v;
u--; v--;
g[u].pb(v);
g[v].pb(u);
}
dfs(0, -1);
int dp[n][41];
for(auto &i:dp){
for(auto &j:i)j = 1;
}
for(int i = 0; i < n; i++)cin >> dp[i][0];
int q;
cin >> q;
while(q--){
int type, x;
cin >> type >> x;
x--;
if(type == 1){
int d, c;
cin >> d >> c;
while(1){
dp[x][d] = dp[x][d] * c % m;
if(d-- == 0) break;
dp[x][d] = dp[x][d] * c % m;
if(x) x = pre[x];
else if(d-- == 0) break;
}
}
else{
int ans = 1;
for(int d = 0; d <= 40 && x >= 0; d++, x = pre[x]){
ans = ans * dp[x][d] % m;
}
cout << ans << '\n';
}
}
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t = 1;
//~ cin >> t;
while(t--){
solve();
}
}
Compilation message
sprinkler.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6748 KB |
Output is correct |
5 |
Correct |
3 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6832 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6544 KB |
Output is correct |
11 |
Correct |
2 ms |
6324 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6524 KB |
Output is correct |
14 |
Correct |
2 ms |
6488 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6548 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6320 KB |
Output is correct |
22 |
Correct |
2 ms |
6548 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
438 ms |
89936 KB |
Output is correct |
3 |
Correct |
286 ms |
90472 KB |
Output is correct |
4 |
Correct |
411 ms |
88912 KB |
Output is correct |
5 |
Correct |
362 ms |
90168 KB |
Output is correct |
6 |
Correct |
262 ms |
89684 KB |
Output is correct |
7 |
Correct |
287 ms |
90456 KB |
Output is correct |
8 |
Correct |
222 ms |
90704 KB |
Output is correct |
9 |
Correct |
541 ms |
88656 KB |
Output is correct |
10 |
Correct |
306 ms |
89172 KB |
Output is correct |
11 |
Correct |
401 ms |
89936 KB |
Output is correct |
12 |
Correct |
282 ms |
84564 KB |
Output is correct |
13 |
Correct |
194 ms |
84932 KB |
Output is correct |
14 |
Correct |
210 ms |
84916 KB |
Output is correct |
15 |
Correct |
205 ms |
84772 KB |
Output is correct |
16 |
Correct |
209 ms |
84820 KB |
Output is correct |
17 |
Correct |
220 ms |
85588 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6548 KB |
Output is correct |
20 |
Correct |
2 ms |
6488 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
438 ms |
89936 KB |
Output is correct |
3 |
Correct |
286 ms |
90472 KB |
Output is correct |
4 |
Correct |
411 ms |
88912 KB |
Output is correct |
5 |
Correct |
362 ms |
90168 KB |
Output is correct |
6 |
Correct |
262 ms |
89684 KB |
Output is correct |
7 |
Correct |
287 ms |
90456 KB |
Output is correct |
8 |
Correct |
222 ms |
90704 KB |
Output is correct |
9 |
Correct |
541 ms |
88656 KB |
Output is correct |
10 |
Correct |
306 ms |
89172 KB |
Output is correct |
11 |
Correct |
401 ms |
89936 KB |
Output is correct |
12 |
Correct |
282 ms |
84564 KB |
Output is correct |
13 |
Correct |
194 ms |
84932 KB |
Output is correct |
14 |
Correct |
210 ms |
84916 KB |
Output is correct |
15 |
Correct |
205 ms |
84772 KB |
Output is correct |
16 |
Correct |
209 ms |
84820 KB |
Output is correct |
17 |
Correct |
220 ms |
85588 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6548 KB |
Output is correct |
20 |
Correct |
2 ms |
6488 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
3 ms |
6492 KB |
Output is correct |
24 |
Correct |
427 ms |
85892 KB |
Output is correct |
25 |
Correct |
282 ms |
84536 KB |
Output is correct |
26 |
Correct |
388 ms |
84308 KB |
Output is correct |
27 |
Correct |
369 ms |
85332 KB |
Output is correct |
28 |
Correct |
267 ms |
85476 KB |
Output is correct |
29 |
Correct |
279 ms |
85336 KB |
Output is correct |
30 |
Correct |
222 ms |
86060 KB |
Output is correct |
31 |
Correct |
496 ms |
84888 KB |
Output is correct |
32 |
Correct |
314 ms |
83528 KB |
Output is correct |
33 |
Correct |
412 ms |
86104 KB |
Output is correct |
34 |
Correct |
300 ms |
84576 KB |
Output is correct |
35 |
Correct |
2 ms |
6488 KB |
Output is correct |
36 |
Correct |
2 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6552 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6488 KB |
Output is correct |
40 |
Correct |
2 ms |
6492 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6540 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6544 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6544 KB |
Output is correct |
48 |
Correct |
2 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
549 ms |
85976 KB |
Output is correct |
3 |
Correct |
641 ms |
86604 KB |
Output is correct |
4 |
Correct |
543 ms |
85956 KB |
Output is correct |
5 |
Correct |
515 ms |
87156 KB |
Output is correct |
6 |
Correct |
287 ms |
87376 KB |
Output is correct |
7 |
Correct |
277 ms |
87384 KB |
Output is correct |
8 |
Correct |
245 ms |
87796 KB |
Output is correct |
9 |
Correct |
569 ms |
86088 KB |
Output is correct |
10 |
Correct |
644 ms |
86516 KB |
Output is correct |
11 |
Correct |
514 ms |
86856 KB |
Output is correct |
12 |
Correct |
481 ms |
87732 KB |
Output is correct |
13 |
Correct |
359 ms |
88660 KB |
Output is correct |
14 |
Correct |
356 ms |
89396 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6324 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
652 ms |
88776 KB |
Output is correct |
3 |
Correct |
658 ms |
82620 KB |
Output is correct |
4 |
Correct |
563 ms |
83760 KB |
Output is correct |
5 |
Correct |
416 ms |
84616 KB |
Output is correct |
6 |
Correct |
343 ms |
84948 KB |
Output is correct |
7 |
Correct |
293 ms |
84820 KB |
Output is correct |
8 |
Correct |
237 ms |
84644 KB |
Output is correct |
9 |
Correct |
518 ms |
84864 KB |
Output is correct |
10 |
Correct |
668 ms |
82368 KB |
Output is correct |
11 |
Correct |
445 ms |
85720 KB |
Output is correct |
12 |
Correct |
526 ms |
83804 KB |
Output is correct |
13 |
Correct |
350 ms |
84392 KB |
Output is correct |
14 |
Correct |
401 ms |
85200 KB |
Output is correct |
15 |
Correct |
2 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6748 KB |
Output is correct |
5 |
Correct |
3 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6832 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6544 KB |
Output is correct |
11 |
Correct |
2 ms |
6324 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6524 KB |
Output is correct |
14 |
Correct |
2 ms |
6488 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6548 KB |
Output is correct |
18 |
Correct |
2 ms |
6744 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6320 KB |
Output is correct |
22 |
Correct |
2 ms |
6548 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6488 KB |
Output is correct |
30 |
Correct |
438 ms |
89936 KB |
Output is correct |
31 |
Correct |
286 ms |
90472 KB |
Output is correct |
32 |
Correct |
411 ms |
88912 KB |
Output is correct |
33 |
Correct |
362 ms |
90168 KB |
Output is correct |
34 |
Correct |
262 ms |
89684 KB |
Output is correct |
35 |
Correct |
287 ms |
90456 KB |
Output is correct |
36 |
Correct |
222 ms |
90704 KB |
Output is correct |
37 |
Correct |
541 ms |
88656 KB |
Output is correct |
38 |
Correct |
306 ms |
89172 KB |
Output is correct |
39 |
Correct |
401 ms |
89936 KB |
Output is correct |
40 |
Correct |
282 ms |
84564 KB |
Output is correct |
41 |
Correct |
194 ms |
84932 KB |
Output is correct |
42 |
Correct |
210 ms |
84916 KB |
Output is correct |
43 |
Correct |
205 ms |
84772 KB |
Output is correct |
44 |
Correct |
209 ms |
84820 KB |
Output is correct |
45 |
Correct |
220 ms |
85588 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6548 KB |
Output is correct |
48 |
Correct |
2 ms |
6488 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
3 ms |
6492 KB |
Output is correct |
52 |
Correct |
427 ms |
85892 KB |
Output is correct |
53 |
Correct |
282 ms |
84536 KB |
Output is correct |
54 |
Correct |
388 ms |
84308 KB |
Output is correct |
55 |
Correct |
369 ms |
85332 KB |
Output is correct |
56 |
Correct |
267 ms |
85476 KB |
Output is correct |
57 |
Correct |
279 ms |
85336 KB |
Output is correct |
58 |
Correct |
222 ms |
86060 KB |
Output is correct |
59 |
Correct |
496 ms |
84888 KB |
Output is correct |
60 |
Correct |
314 ms |
83528 KB |
Output is correct |
61 |
Correct |
412 ms |
86104 KB |
Output is correct |
62 |
Correct |
300 ms |
84576 KB |
Output is correct |
63 |
Correct |
2 ms |
6488 KB |
Output is correct |
64 |
Correct |
2 ms |
6492 KB |
Output is correct |
65 |
Correct |
2 ms |
6552 KB |
Output is correct |
66 |
Correct |
2 ms |
6492 KB |
Output is correct |
67 |
Correct |
2 ms |
6488 KB |
Output is correct |
68 |
Correct |
2 ms |
6492 KB |
Output is correct |
69 |
Correct |
2 ms |
6492 KB |
Output is correct |
70 |
Correct |
2 ms |
6492 KB |
Output is correct |
71 |
Correct |
2 ms |
6540 KB |
Output is correct |
72 |
Correct |
2 ms |
6492 KB |
Output is correct |
73 |
Correct |
2 ms |
6544 KB |
Output is correct |
74 |
Correct |
2 ms |
6492 KB |
Output is correct |
75 |
Correct |
2 ms |
6544 KB |
Output is correct |
76 |
Correct |
2 ms |
6492 KB |
Output is correct |
77 |
Correct |
2 ms |
6492 KB |
Output is correct |
78 |
Correct |
2 ms |
6492 KB |
Output is correct |
79 |
Correct |
549 ms |
85976 KB |
Output is correct |
80 |
Correct |
641 ms |
86604 KB |
Output is correct |
81 |
Correct |
543 ms |
85956 KB |
Output is correct |
82 |
Correct |
515 ms |
87156 KB |
Output is correct |
83 |
Correct |
287 ms |
87376 KB |
Output is correct |
84 |
Correct |
277 ms |
87384 KB |
Output is correct |
85 |
Correct |
245 ms |
87796 KB |
Output is correct |
86 |
Correct |
569 ms |
86088 KB |
Output is correct |
87 |
Correct |
644 ms |
86516 KB |
Output is correct |
88 |
Correct |
514 ms |
86856 KB |
Output is correct |
89 |
Correct |
481 ms |
87732 KB |
Output is correct |
90 |
Correct |
359 ms |
88660 KB |
Output is correct |
91 |
Correct |
356 ms |
89396 KB |
Output is correct |
92 |
Correct |
2 ms |
6492 KB |
Output is correct |
93 |
Correct |
2 ms |
6744 KB |
Output is correct |
94 |
Correct |
2 ms |
6324 KB |
Output is correct |
95 |
Correct |
2 ms |
6492 KB |
Output is correct |
96 |
Correct |
2 ms |
6492 KB |
Output is correct |
97 |
Correct |
2 ms |
6492 KB |
Output is correct |
98 |
Correct |
652 ms |
88776 KB |
Output is correct |
99 |
Correct |
658 ms |
82620 KB |
Output is correct |
100 |
Correct |
563 ms |
83760 KB |
Output is correct |
101 |
Correct |
416 ms |
84616 KB |
Output is correct |
102 |
Correct |
343 ms |
84948 KB |
Output is correct |
103 |
Correct |
293 ms |
84820 KB |
Output is correct |
104 |
Correct |
237 ms |
84644 KB |
Output is correct |
105 |
Correct |
518 ms |
84864 KB |
Output is correct |
106 |
Correct |
668 ms |
82368 KB |
Output is correct |
107 |
Correct |
445 ms |
85720 KB |
Output is correct |
108 |
Correct |
526 ms |
83804 KB |
Output is correct |
109 |
Correct |
350 ms |
84392 KB |
Output is correct |
110 |
Correct |
401 ms |
85200 KB |
Output is correct |
111 |
Correct |
2 ms |
6488 KB |
Output is correct |
112 |
Correct |
2 ms |
6492 KB |
Output is correct |
113 |
Correct |
2 ms |
6492 KB |
Output is correct |
114 |
Correct |
2 ms |
6492 KB |
Output is correct |
115 |
Correct |
2 ms |
6492 KB |
Output is correct |
116 |
Correct |
514 ms |
83856 KB |
Output is correct |
117 |
Correct |
521 ms |
84892 KB |
Output is correct |
118 |
Correct |
517 ms |
84440 KB |
Output is correct |
119 |
Correct |
441 ms |
85416 KB |
Output is correct |
120 |
Correct |
324 ms |
85376 KB |
Output is correct |
121 |
Correct |
333 ms |
85684 KB |
Output is correct |
122 |
Correct |
245 ms |
86028 KB |
Output is correct |
123 |
Correct |
548 ms |
84816 KB |
Output is correct |
124 |
Correct |
704 ms |
83444 KB |
Output is correct |
125 |
Correct |
443 ms |
85496 KB |
Output is correct |
126 |
Correct |
575 ms |
84756 KB |
Output is correct |
127 |
Correct |
535 ms |
84760 KB |
Output is correct |
128 |
Correct |
473 ms |
85648 KB |
Output is correct |
129 |
Correct |
467 ms |
86612 KB |
Output is correct |