//Emmanuel B
//Sprinker
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
#define pb push_back
#define deb(x) cout<<#x<<": "<<x<<endl;
#define deb2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
void dfs(lli n, lli par, vector<lli> &parent, vector<vector<lli>> &adj, vector<vector<lli>> &sons){
parent[n]=par;
for(lli x: adj[n]){
if(x==par) continue;
sons[n].pb(x);
dfs(x,n,parent,adj,sons);
}
}
lli L;
void update(lli n, lli p, vector<vector<lli>> &adj, lli c, vector<lli> &values, lli &w){
if(c<0) return;
values[n]*=w;
values[n]%=L;
if(c==0) return;
for(lli x: adj[n]){
if(x==p) continue;
update(x,n,adj,c-1, values, w);
}
}
int main(){
lli N;
cin>>N>>L;
vector<vector<lli>> adj (N+5);
for(lli i=0; i<N-1; ++i){
lli a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
vector<lli> parent (N+5);
vector<vector<lli>> sons (N+5);
dfs(1,0,parent,adj,sons);
vector<lli> values (N+5);
for(lli i=1; i<=N; ++i){
cin>>values[i];
}
lli Q;
cin>>Q;
while(Q--){
lli type;
cin>>type;
if(type==1){
lli x,d,w;
cin>>x>>d>>w;
update(x, -1, adj, d, values, w);
}
else{
lli x;
cin>>x;
cout<<values[x]<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
424 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
683 ms |
36264 KB |
Output is correct |
3 |
Correct |
455 ms |
36952 KB |
Output is correct |
4 |
Correct |
607 ms |
51536 KB |
Output is correct |
5 |
Correct |
520 ms |
36500 KB |
Output is correct |
6 |
Correct |
560 ms |
35664 KB |
Output is correct |
7 |
Correct |
586 ms |
36092 KB |
Output is correct |
8 |
Correct |
481 ms |
34620 KB |
Output is correct |
9 |
Correct |
604 ms |
58448 KB |
Output is correct |
10 |
Correct |
413 ms |
57144 KB |
Output is correct |
11 |
Correct |
609 ms |
36160 KB |
Output is correct |
12 |
Correct |
455 ms |
36712 KB |
Output is correct |
13 |
Execution timed out |
4041 ms |
27260 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
683 ms |
36264 KB |
Output is correct |
3 |
Correct |
455 ms |
36952 KB |
Output is correct |
4 |
Correct |
607 ms |
51536 KB |
Output is correct |
5 |
Correct |
520 ms |
36500 KB |
Output is correct |
6 |
Correct |
560 ms |
35664 KB |
Output is correct |
7 |
Correct |
586 ms |
36092 KB |
Output is correct |
8 |
Correct |
481 ms |
34620 KB |
Output is correct |
9 |
Correct |
604 ms |
58448 KB |
Output is correct |
10 |
Correct |
413 ms |
57144 KB |
Output is correct |
11 |
Correct |
609 ms |
36160 KB |
Output is correct |
12 |
Correct |
455 ms |
36712 KB |
Output is correct |
13 |
Execution timed out |
4041 ms |
27260 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
741 ms |
55092 KB |
Output is correct |
3 |
Correct |
1798 ms |
50904 KB |
Output is correct |
4 |
Correct |
857 ms |
51284 KB |
Output is correct |
5 |
Correct |
2845 ms |
33364 KB |
Output is correct |
6 |
Execution timed out |
4065 ms |
28584 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
848 ms |
50772 KB |
Output is correct |
3 |
Correct |
1859 ms |
46360 KB |
Output is correct |
4 |
Correct |
911 ms |
48724 KB |
Output is correct |
5 |
Correct |
2937 ms |
35148 KB |
Output is correct |
6 |
Execution timed out |
4091 ms |
28796 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
424 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
683 ms |
36264 KB |
Output is correct |
31 |
Correct |
455 ms |
36952 KB |
Output is correct |
32 |
Correct |
607 ms |
51536 KB |
Output is correct |
33 |
Correct |
520 ms |
36500 KB |
Output is correct |
34 |
Correct |
560 ms |
35664 KB |
Output is correct |
35 |
Correct |
586 ms |
36092 KB |
Output is correct |
36 |
Correct |
481 ms |
34620 KB |
Output is correct |
37 |
Correct |
604 ms |
58448 KB |
Output is correct |
38 |
Correct |
413 ms |
57144 KB |
Output is correct |
39 |
Correct |
609 ms |
36160 KB |
Output is correct |
40 |
Correct |
455 ms |
36712 KB |
Output is correct |
41 |
Execution timed out |
4041 ms |
27260 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |