This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Quick Note :
* Jangan Mikir Lama - lama, sampahin dulu aja kalo OI
* Always Try to reset
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 2e5 + 5;
ll n, q, l;
ll a[nax], isZero[nax], par[nax];
ll mul[nax][5];
vector<vector<ll>> v(nax);
void find_par(ll idx, ll bfr){
par[idx] = bfr;
for(auto it : v[idx]){
if(it != bfr){
find_par(it, idx);
}
}
}
void upd_val(ll x, ll d, ll w){
if(d < 0 || x == 0) return;
if(x == 1){
for(ll i = d; i >= 0; i--) mul[x][i] = (mul[x][i] * w) % l;
return;
}
mul[x][d] *= w;
mul[x][d] %= l;
if(d - 1 >= 0){
mul[x][d-1] *= w;
mul[x][d-1] %= l;
}
upd_val(par[x], d - 1, w);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
cin >> n >> l;
for(ll i = 1; i <= n; i++){
for(ll j = 0; j < 5; j++){
mul[i][j] = 1;
}
}
for(ll i = 1; i < n; i++){
ll x, y;
cin >> x >> y;
v[x].pb(y);
v[y].pb(x);
}
for(ll i = 1; i <= n; i++){
cin >> a[i];
}
find_par(1, 0);
cin >> q;
while(q--){
ll tp, x, d, w;
cin >> tp;
if(tp == 1){
cin >> x >> d >> w;
upd_val(x, d, w);
}
else{
cin >> x;
ll ans = a[x] * mul[x][0] % l;
if(par[x] == 1){
ans = (ans * mul[par[x]][1]) % l;
//ans = (ans * mul[par[x]][2]) % l;
}
else if(par[x] == 0){
//ans = (ans * mul[x][1]) % l;
//ans = (ans * mul[x][2]) % l;
}
else{
ans = (ans * mul[par[x]][1]) % l;
//ans = (ans * mul[par[par[x]]][2]) % l;
ans = (ans * mul[par[par[x]]][2]) % l;
}
cout << ans << '\n';
}
}
}
# | 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... |