#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
const ll MAXN = 2E5+16;
vll adj[MAXN];
ll L;
vll ve;
ll par[MAXN];
ll src[MAXN];
void dfs (ll u, ll par) {
::par[u] = par;
for (ll v : adj[u]) {
if (v == par) continue;
dfs(v, u);
}
}
int main () {
cin.tie(nullptr) -> sync_with_stdio(false);
ll n;
cin >> n >> L;
fill(src, src+n, 1);
for (ll i = 1; i < n; i++) {
ll u, v;
cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
ve = vll(n);
for (ll &i : ve) cin >> i;
dfs(0, 0);
ll Q;
cin >> Q;
for (ll q = 0; q < Q; q++) {
char type;
cin >> type;
switch (type) {
case '1':
{ll u, maxD, w;
cin >> u >> maxD >> w;
u--;
if (maxD == 0) {
(ve[u] *= w) %= L;
} else {
if (u) (ve[par[u]] *= w) %= L;
(ve[u] *= w) %= L;
(src[u] *= w) %= L;
}
break;}
case '2':
{ll u;
cin >> u;
u--;
ll ans = ve[u];
if (u) (ans *= src[par[u]]) %= L;
cout << ans << '\n';
break;}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
158 ms |
28908 KB |
Output is correct |
3 |
Correct |
172 ms |
29264 KB |
Output is correct |
4 |
Correct |
148 ms |
31572 KB |
Output is correct |
5 |
Correct |
162 ms |
29200 KB |
Output is correct |
6 |
Correct |
151 ms |
28676 KB |
Output is correct |
7 |
Correct |
156 ms |
29540 KB |
Output is correct |
8 |
Correct |
139 ms |
29576 KB |
Output is correct |
9 |
Correct |
154 ms |
32852 KB |
Output is correct |
10 |
Correct |
167 ms |
33184 KB |
Output is correct |
11 |
Correct |
204 ms |
28756 KB |
Output is correct |
12 |
Correct |
165 ms |
29272 KB |
Output is correct |
13 |
Correct |
135 ms |
29376 KB |
Output is correct |
14 |
Correct |
141 ms |
29880 KB |
Output is correct |
15 |
Correct |
132 ms |
29036 KB |
Output is correct |
16 |
Correct |
138 ms |
29596 KB |
Output is correct |
17 |
Correct |
166 ms |
30308 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5176 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
158 ms |
28908 KB |
Output is correct |
3 |
Correct |
172 ms |
29264 KB |
Output is correct |
4 |
Correct |
148 ms |
31572 KB |
Output is correct |
5 |
Correct |
162 ms |
29200 KB |
Output is correct |
6 |
Correct |
151 ms |
28676 KB |
Output is correct |
7 |
Correct |
156 ms |
29540 KB |
Output is correct |
8 |
Correct |
139 ms |
29576 KB |
Output is correct |
9 |
Correct |
154 ms |
32852 KB |
Output is correct |
10 |
Correct |
167 ms |
33184 KB |
Output is correct |
11 |
Correct |
204 ms |
28756 KB |
Output is correct |
12 |
Correct |
165 ms |
29272 KB |
Output is correct |
13 |
Correct |
135 ms |
29376 KB |
Output is correct |
14 |
Correct |
141 ms |
29880 KB |
Output is correct |
15 |
Correct |
132 ms |
29036 KB |
Output is correct |
16 |
Correct |
138 ms |
29596 KB |
Output is correct |
17 |
Correct |
166 ms |
30308 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5176 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Incorrect |
151 ms |
28876 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
193 ms |
32124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |