#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n"){
for(auto item: container) cout << item << separator;
cout << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 2e5 + 69, D = 40;
int n, l, q;
vector<int> graph[N];
ll val[N][D + 1];
int parent[N];
void dfs(int u,int p){
parent[u] = p;
for(int v: graph[u]) if (v != p){
dfs(v, u);
}
}
void mul(ll &x, ll y){
x = x * y % l;
}
void solve(){
cin >> n >> l;
for(int i = 1; i < n; ++i){
int u, v; cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(1, 0);
vector<ll> h(n+1);
for(int i = 1; i<=n; ++i) cin >> h[i];
for(int i = 1; i <= n; ++i) for(int j = 0; j <= D; ++j) val[i][j] = 1;
cin >> q;
while(q--){
int type; cin >> type;
if (type == 1){
int x, d, w; cin >> x >> d >> w;
for(int j = d; j >= 0; --j){
if (x == 0) break;
mul(val[x][j], w);
if (j > 0) mul(val[x][j-1], w);
if (x == 1 && j > 1){
for(int t = 0; t < j - 1; ++t)
mul(val[x][t], w);
}
x = parent[x];
}
}
else{
int x; cin >> x;
ll ans = h[x];
for(int j = 0; j <= D; ++j){
if (x == 0) break;
mul(ans, val[x][j]);
x = parent[x];
}
cout << ans << "\n";
}
}
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t start = clock();
solve();
cerr << "Time elapsed: " << clock() - start << "ms!\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |