#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vec vector
#define arr array
const int MXN = 200'005;
const int MXD = 40;
int pars[MXN];
vec<int> tree[MXN];
void dfs0(int u = 0, int p = -1) {
pars[u] = p;
for(int v : tree[u]) {
if(v == p) continue;
dfs0(v, u);
}
}
int32_t main() {
int N, L;
cin >> N >> L;
for(int i = 0; i<N-1; i++) {
int u, v;
cin >> u >> v;
u--,v--;
tree[u].push_back(v);
tree[v].push_back(u);
}
dfs0();
vec<vec<int>> contr(N, vec<int>(MXD+1, 1));
for(int i = 0; i<N; i++) {
int h;
cin >> h;
contr[i][0] = h;
}
int Q;
cin >> Q;
while(Q--) {
int t, u;
cin >> t >> u;
u--;
if(t==1) {
int d, m;
cin >> d >> m;
while(u != -1 && d >= 0) {
//cerr <<"UPD: " << u << '\n';
contr[u][d] *= m;
contr[u][d] %= L;
u = pars[u];
d--;
}
//cerr <<"----------" << '\n';
if(false){
for(int i = 0; i<N; i++) {
for(int j = 0; j<5; j++) {
cerr << contr[i][j] << ' ';
}
cerr << '\n';
}
cerr << '\n';
}
//cerr << "------------------" << '\n';
}
else {
assert(t==2);
int res = 1;
for(int i = 0; i<MXD && u != -1; i++) {
for(int j = i; j<((pars[u] == -1) ? (MXD+1) : (i+2)); j++) {
res *= contr[u][j];
res %= L;
//cerr << "MUL: " << res << '\n';
}
u = pars[u];
}
cout << res << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1062 ms |
96168 KB |
Output is correct |
3 |
Correct |
639 ms |
96596 KB |
Output is correct |
4 |
Correct |
914 ms |
98772 KB |
Output is correct |
5 |
Correct |
780 ms |
96512 KB |
Output is correct |
6 |
Correct |
655 ms |
96084 KB |
Output is correct |
7 |
Correct |
681 ms |
96852 KB |
Output is correct |
8 |
Correct |
583 ms |
96980 KB |
Output is correct |
9 |
Correct |
1128 ms |
100356 KB |
Output is correct |
10 |
Correct |
510 ms |
100432 KB |
Output is correct |
11 |
Correct |
966 ms |
96184 KB |
Output is correct |
12 |
Correct |
582 ms |
96596 KB |
Output is correct |
13 |
Correct |
402 ms |
96596 KB |
Output is correct |
14 |
Correct |
384 ms |
97208 KB |
Output is correct |
15 |
Correct |
380 ms |
96364 KB |
Output is correct |
16 |
Correct |
385 ms |
97104 KB |
Output is correct |
17 |
Correct |
429 ms |
97444 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1062 ms |
96168 KB |
Output is correct |
3 |
Correct |
639 ms |
96596 KB |
Output is correct |
4 |
Correct |
914 ms |
98772 KB |
Output is correct |
5 |
Correct |
780 ms |
96512 KB |
Output is correct |
6 |
Correct |
655 ms |
96084 KB |
Output is correct |
7 |
Correct |
681 ms |
96852 KB |
Output is correct |
8 |
Correct |
583 ms |
96980 KB |
Output is correct |
9 |
Correct |
1128 ms |
100356 KB |
Output is correct |
10 |
Correct |
510 ms |
100432 KB |
Output is correct |
11 |
Correct |
966 ms |
96184 KB |
Output is correct |
12 |
Correct |
582 ms |
96596 KB |
Output is correct |
13 |
Correct |
402 ms |
96596 KB |
Output is correct |
14 |
Correct |
384 ms |
97208 KB |
Output is correct |
15 |
Correct |
380 ms |
96364 KB |
Output is correct |
16 |
Correct |
385 ms |
97104 KB |
Output is correct |
17 |
Correct |
429 ms |
97444 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
1 ms |
4956 KB |
Output is correct |
24 |
Correct |
877 ms |
96072 KB |
Output is correct |
25 |
Correct |
463 ms |
96616 KB |
Output is correct |
26 |
Correct |
704 ms |
100436 KB |
Output is correct |
27 |
Correct |
676 ms |
96400 KB |
Output is correct |
28 |
Correct |
575 ms |
96592 KB |
Output is correct |
29 |
Correct |
571 ms |
96340 KB |
Output is correct |
30 |
Correct |
548 ms |
97216 KB |
Output is correct |
31 |
Correct |
912 ms |
98712 KB |
Output is correct |
32 |
Correct |
493 ms |
100612 KB |
Output is correct |
33 |
Correct |
899 ms |
96220 KB |
Output is correct |
34 |
Correct |
452 ms |
96736 KB |
Output is correct |
35 |
Correct |
3 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
4956 KB |
Output is correct |
42 |
Correct |
1 ms |
4956 KB |
Output is correct |
43 |
Correct |
2 ms |
4956 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4964 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
1 ms |
4956 KB |
Output is correct |
48 |
Correct |
3 ms |
4952 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
959 ms |
97440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
950 ms |
98220 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |