#include <bits/stdc++.h>
using namespace std;
int main(){
long long n, l; cin >> n >> l;
vector<vector<long long>> adj(n, vector<long long>());
long long a, b;
for(long long i = 0; i < n - 1; i ++){
cin >> a >> b; a -= 1; b -= 1;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<long long> heights(n, 0);
long long z;
for(long long i = 0; i < n; i ++){
cin >> z;
heights[i] = z;
}
long long queries; cin >> queries;
long long t;
long long x, d, w;
vector<long long> res;
for(long long i = 0; i < queries; i ++){
cin >> t;
if(t == 1){
cin >> x >> d >> w;
x -= 1;
queue<vector<long long>> q;
q.push({0, x});
long long node, dist, parent;
while(!q.empty()){
node = q.front()[1];
dist = q.front()[0];
parent = q.front()[2];
heights[node] *= w;
heights[node] %= l;
q.pop();
for(long long i = 0; i < adj[node].size(); i ++){
if(adj[node][i] != parent and dist < d){
q.push({dist + 1, adj[node][i], node});
}
}
}
} else {
cin >> x;
res.push_back(heights[x-1]);
}
}
for(long long i = 0; i < res.size(); i ++){
cout << res[i] << "\n";
}
}
/*
g++ -std=gnu++17 -O2 -pipe -static -o joi joi.cpp
4 7
1 2
2 3
3 4
1
1
1
1
11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
*/
Compilation message
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:39:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(long long i = 0; i < adj[node].size(); i ++){
| ~~^~~~~~~~~~~~~~~~~~
sprinkler.cpp:50:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(long long i = 0; i < res.size(); i ++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
678 ms |
16964 KB |
Output is correct |
3 |
Correct |
3515 ms |
13424 KB |
Output is correct |
4 |
Correct |
1156 ms |
15072 KB |
Output is correct |
5 |
Execution timed out |
4056 ms |
14980 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |