#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define endl '\n'
#define pb push_back
using pi = array<int, 2>;
const int N = 2e5 + 5;
vector<int> adj[N];
int par[N];
const int D = 42;
int h[N], wch[D][N];
void dfs(int u) {
for (int v : adj[u]) {
if (v == par[u]) continue;
par[v] = u;
dfs(v);
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, l;
cin >> n >> l;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
for (int i = 0; i <= n; ++i) {
for (int d = 0; d < D; ++d) wch[d][i] = 1;
}
dfs(1);
for (int i = 1; i <= n; ++i) cin >> h[i];
int q;
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int u, d, w;
cin >> u >> d >> w;
auto mult = [&](int& var) {
var = var * w % l;
};
int p = u;
for (int i = 0; i <= d; ++i) {
int descend = d - i;
for (int j = 0; j <= descend; ++j) mult(wch[j][p]);
p = par[u];
}
} else {
int u;
cin >> u;
int p = u;
int ans = h[u];
for (int d = 0; d < D; ++d) {
ans = ans * wch[d][p] % l;
p = par[p];
}
cout << ans << endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
65632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
65628 KB |
Output is correct |
2 |
Correct |
488 ms |
92996 KB |
Output is correct |
3 |
Correct |
270 ms |
93524 KB |
Output is correct |
4 |
Correct |
410 ms |
95628 KB |
Output is correct |
5 |
Correct |
370 ms |
93384 KB |
Output is correct |
6 |
Correct |
276 ms |
92956 KB |
Output is correct |
7 |
Correct |
304 ms |
93608 KB |
Output is correct |
8 |
Correct |
251 ms |
93836 KB |
Output is correct |
9 |
Correct |
557 ms |
97104 KB |
Output is correct |
10 |
Correct |
307 ms |
97360 KB |
Output is correct |
11 |
Correct |
498 ms |
92920 KB |
Output is correct |
12 |
Correct |
264 ms |
93396 KB |
Output is correct |
13 |
Correct |
211 ms |
93612 KB |
Output is correct |
14 |
Correct |
201 ms |
93976 KB |
Output is correct |
15 |
Correct |
190 ms |
93304 KB |
Output is correct |
16 |
Correct |
208 ms |
93788 KB |
Output is correct |
17 |
Correct |
227 ms |
94456 KB |
Output is correct |
18 |
Correct |
10 ms |
65624 KB |
Output is correct |
19 |
Correct |
9 ms |
67676 KB |
Output is correct |
20 |
Correct |
9 ms |
65780 KB |
Output is correct |
21 |
Correct |
9 ms |
61532 KB |
Output is correct |
22 |
Correct |
9 ms |
63496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
65628 KB |
Output is correct |
2 |
Correct |
488 ms |
92996 KB |
Output is correct |
3 |
Correct |
270 ms |
93524 KB |
Output is correct |
4 |
Correct |
410 ms |
95628 KB |
Output is correct |
5 |
Correct |
370 ms |
93384 KB |
Output is correct |
6 |
Correct |
276 ms |
92956 KB |
Output is correct |
7 |
Correct |
304 ms |
93608 KB |
Output is correct |
8 |
Correct |
251 ms |
93836 KB |
Output is correct |
9 |
Correct |
557 ms |
97104 KB |
Output is correct |
10 |
Correct |
307 ms |
97360 KB |
Output is correct |
11 |
Correct |
498 ms |
92920 KB |
Output is correct |
12 |
Correct |
264 ms |
93396 KB |
Output is correct |
13 |
Correct |
211 ms |
93612 KB |
Output is correct |
14 |
Correct |
201 ms |
93976 KB |
Output is correct |
15 |
Correct |
190 ms |
93304 KB |
Output is correct |
16 |
Correct |
208 ms |
93788 KB |
Output is correct |
17 |
Correct |
227 ms |
94456 KB |
Output is correct |
18 |
Correct |
10 ms |
65624 KB |
Output is correct |
19 |
Correct |
9 ms |
67676 KB |
Output is correct |
20 |
Correct |
9 ms |
65780 KB |
Output is correct |
21 |
Correct |
9 ms |
61532 KB |
Output is correct |
22 |
Correct |
9 ms |
63496 KB |
Output is correct |
23 |
Correct |
8 ms |
63584 KB |
Output is correct |
24 |
Incorrect |
511 ms |
93096 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
63572 KB |
Output is correct |
2 |
Incorrect |
748 ms |
94416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
57436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
65632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |