#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int N = 2e5 + 10;
vector<int> g[N];
int h[N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, l;
cin >> n >> l;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
g[--u].push_back(--v);
g[v].push_back(u);
}
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
int queries;
cin >> queries;
while (queries--) {
int type;
cin >> type;
if (type == 1) {
int x, d, w;
cin >> x >> d >> w;
--x;
queue<tuple<int, int, int>> bfs;
bfs.push({0, x, -1});
while (sz(bfs)) {
auto [cd, u, p] = bfs.front();
bfs.pop();
(h[u] *= w) %= l;
if (cd == d) {
continue;
}
for (int v : g[u]) {
if (v != p) {
bfs.push({cd + 1, v, u});
}
}
}
} else {
int x;
cin >> x;
cout << h[x - 1] << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5056 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
203 ms |
15608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
203 ms |
15608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
479 ms |
12892 KB |
Output is correct |
3 |
Correct |
2663 ms |
12320 KB |
Output is correct |
4 |
Correct |
926 ms |
12388 KB |
Output is correct |
5 |
Execution timed out |
4082 ms |
12396 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5000 KB |
Output is correct |
2 |
Correct |
549 ms |
15604 KB |
Output is correct |
3 |
Correct |
2666 ms |
12636 KB |
Output is correct |
4 |
Correct |
872 ms |
13856 KB |
Output is correct |
5 |
Execution timed out |
4054 ms |
13808 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5056 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |