#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<ll>> tree;
vector<ll> initialHeights;
vector<bool>visited;
void dfs(ll current, ll parent, ll L, ll W, ll pos, ll size) {
if(size==pos)return;
ll newHeight = (initialHeights[current] * W) % L;
initialHeights[current] = newHeight;
visited[current]=true;
for (ll neighbor : tree[current]) {
if (neighbor != parent&&!visited[neighbor]) {
dfs(neighbor, current, L, W,pos+1,size);
}
}
}
int main() {
ll N, L;
cin >> N >> L;
tree.resize(N + 1);
initialHeights.resize(N + 1);
for (ll i = 1; i <= N - 1; ++i) {
ll A, B;
cin >> A >> B;
tree[A].push_back(B);
tree[B].push_back(A);
}
for (ll i = 1; i <= N; ++i) {
cin >> initialHeights[i];
}
ll Q;
cin >> Q;
for (ll i = 1; i <= Q; ++i) {
ll T;
cin >> T;
if (T == 1) {
ll X, D, W;
cin >> X >> D >> W;
visited.resize(N,false);
dfs(X, 0, L, W,0,D);
} else if (T == 2) {
ll X;
cin >> X;
cout << initialHeights[X] << endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
799 ms |
22136 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |