//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);
vector<lli> mult1 (N+5,1);
vector<lli> mult2 (N+5,1);
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;
if(d==0){
values[x]*=w;
values[x]%=L;
}
else{
values[x]*=w;
values[x]%=L;
mult1[x]*=w;
mult1[x]%=L;
mult2[parent[x]]*=w;
mult2[parent[x]]%=L;
}
}
else{
lli x;
cin>>x;
lli ans=values[x]*mult2[x];
ans%=L;
ans*=mult1[parent[x]];
ans%=L;
cout<<ans<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
760 ms |
31232 KB |
Output is correct |
3 |
Correct |
493 ms |
27984 KB |
Output is correct |
4 |
Correct |
624 ms |
44624 KB |
Output is correct |
5 |
Correct |
654 ms |
39644 KB |
Output is correct |
6 |
Correct |
617 ms |
31908 KB |
Output is correct |
7 |
Correct |
610 ms |
38996 KB |
Output is correct |
8 |
Correct |
572 ms |
37692 KB |
Output is correct |
9 |
Correct |
763 ms |
61736 KB |
Output is correct |
10 |
Correct |
528 ms |
60244 KB |
Output is correct |
11 |
Correct |
736 ms |
39288 KB |
Output is correct |
12 |
Correct |
534 ms |
39768 KB |
Output is correct |
13 |
Correct |
410 ms |
37572 KB |
Output is correct |
14 |
Correct |
463 ms |
38544 KB |
Output is correct |
15 |
Correct |
445 ms |
37800 KB |
Output is correct |
16 |
Correct |
431 ms |
38064 KB |
Output is correct |
17 |
Correct |
439 ms |
38996 KB |
Output is correct |
18 |
Correct |
2 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
760 ms |
31232 KB |
Output is correct |
3 |
Correct |
493 ms |
27984 KB |
Output is correct |
4 |
Correct |
624 ms |
44624 KB |
Output is correct |
5 |
Correct |
654 ms |
39644 KB |
Output is correct |
6 |
Correct |
617 ms |
31908 KB |
Output is correct |
7 |
Correct |
610 ms |
38996 KB |
Output is correct |
8 |
Correct |
572 ms |
37692 KB |
Output is correct |
9 |
Correct |
763 ms |
61736 KB |
Output is correct |
10 |
Correct |
528 ms |
60244 KB |
Output is correct |
11 |
Correct |
736 ms |
39288 KB |
Output is correct |
12 |
Correct |
534 ms |
39768 KB |
Output is correct |
13 |
Correct |
410 ms |
37572 KB |
Output is correct |
14 |
Correct |
463 ms |
38544 KB |
Output is correct |
15 |
Correct |
445 ms |
37800 KB |
Output is correct |
16 |
Correct |
431 ms |
38064 KB |
Output is correct |
17 |
Correct |
439 ms |
38996 KB |
Output is correct |
18 |
Correct |
2 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Incorrect |
787 ms |
39216 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
761 ms |
60308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |