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, len;
ll a[nax], par[nax], val[nax];
ll child_mul[nax][45];
vector<ll> v[nax];
void find_par(ll x, ll y){
par[x] = y;
for(auto it : v[x]){
if(it == y) continue;
else{
find_par(it, x);
}
}
}
void dfs_update(ll x, ll dis, ll w){
if(dis < 0 || x == 0) return;
val[x] *= w;
val[x] %= len;
dfs_update(par[x], dis - 1, w);
}
ll dfs_query(ll x, ll dis){
if(dis >= 41 || x == 0) return 1;
ll ret = child_mul[x][dis];
//cout << child_mul[x][dis] << " " << x << " " << dis << '\n';
return (ret * dfs_query(par[x], dis + 1)) % len;
}
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 >> len;
for(ll i = 1; i <= n ; i++){
for(ll j = 1; j <= 40; j++){
child_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 >> val[i];
}
find_par(1, 0);
cin >> q;
while(q--){
ll tp;
cin >> tp;
if(tp == 1){
ll x, d, w;
cin >> x >> d >> w;
for(ll i = 1; i <= d; i++){
child_mul[x][i] *= w;
child_mul[x][i] %= len;
}
val[x] *= w;
val[x] %= len;
dfs_update(par[x], d - 1, w);
}
else{
ll x;
cin >> x;
ll ans = val[x] * dfs_query(par[x], 1);
cout << ans % len << '\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... |