#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;
const int N = 2e5 + 1;
int n, l;
vector<int> g[N];
int h[N], cnt[N];
bool zero[N];
void dfs(int v, int p, int d, int bound, int w) {
h[v] *= w;
h[v] %= l;
if (d == bound) return;
for (int to : g[v]) {
if (to != p) {
dfs(to, v, d + 1, bound, w);
}
}
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> l;
for (int i = 1; i < n; ++i) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
int q;
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int v, d, w;
cin >> v >> d >> w;
if (zero[v]) {
continue;
} else if (w == 1) {
continue;
} else {
if (w == 0) {
zero[v] = true;
dfs(v, -1, 0, d, w);
} else {
if (cnt[v] < 30) {
cnt[v]++;
dfs(v, -1, 0, d, w);
}
}
}
} else {
int v;
cin >> v;
cout << h[v] << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8292 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
3 ms |
8280 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
6 ms |
8368 KB |
Output is correct |
7 |
Correct |
6 ms |
8284 KB |
Output is correct |
8 |
Correct |
6 ms |
8284 KB |
Output is correct |
9 |
Incorrect |
2 ms |
8536 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
149 ms |
18900 KB |
Output is correct |
3 |
Correct |
194 ms |
15832 KB |
Output is correct |
4 |
Correct |
163 ms |
16408 KB |
Output is correct |
5 |
Correct |
172 ms |
17504 KB |
Output is correct |
6 |
Correct |
166 ms |
17300 KB |
Output is correct |
7 |
Correct |
171 ms |
18264 KB |
Output is correct |
8 |
Correct |
150 ms |
17852 KB |
Output is correct |
9 |
Correct |
148 ms |
17744 KB |
Output is correct |
10 |
Correct |
214 ms |
14996 KB |
Output is correct |
11 |
Correct |
145 ms |
19024 KB |
Output is correct |
12 |
Correct |
242 ms |
16108 KB |
Output is correct |
13 |
Incorrect |
181 ms |
16164 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
149 ms |
18900 KB |
Output is correct |
3 |
Correct |
194 ms |
15832 KB |
Output is correct |
4 |
Correct |
163 ms |
16408 KB |
Output is correct |
5 |
Correct |
172 ms |
17504 KB |
Output is correct |
6 |
Correct |
166 ms |
17300 KB |
Output is correct |
7 |
Correct |
171 ms |
18264 KB |
Output is correct |
8 |
Correct |
150 ms |
17852 KB |
Output is correct |
9 |
Correct |
148 ms |
17744 KB |
Output is correct |
10 |
Correct |
214 ms |
14996 KB |
Output is correct |
11 |
Correct |
145 ms |
19024 KB |
Output is correct |
12 |
Correct |
242 ms |
16108 KB |
Output is correct |
13 |
Incorrect |
181 ms |
16164 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
305 ms |
15440 KB |
Output is correct |
3 |
Correct |
878 ms |
24264 KB |
Output is correct |
4 |
Incorrect |
433 ms |
23636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
334 ms |
25844 KB |
Output is correct |
3 |
Correct |
1817 ms |
24572 KB |
Output is correct |
4 |
Correct |
541 ms |
24916 KB |
Output is correct |
5 |
Correct |
3151 ms |
26084 KB |
Output is correct |
6 |
Execution timed out |
4049 ms |
20356 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8292 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
3 ms |
8280 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
6 ms |
8368 KB |
Output is correct |
7 |
Correct |
6 ms |
8284 KB |
Output is correct |
8 |
Correct |
6 ms |
8284 KB |
Output is correct |
9 |
Incorrect |
2 ms |
8536 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |