This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mod = 1e9 + 7;
const int mxn = 2e5, mxr = 25e3, sq = 500, mxv = 1e6 + 5, mxvv = 130;
int n, l;
vt<int>adj[mxn + 1];
ll comp[mxn + 1][41], h[mxn + 5], pa[mxn + 4];
void dfs(int s, int pre){
pa[s] = pre;
for(auto i: adj[s]){
if(i != pre){
dfs(i, s);
}
}
}
void solve(ll x, ll d, ll w){
if(d == -1)return;
if(x == 1){
for(int i = 0; i <= d; i++){
comp[x][i] = (comp[x][i] * w) % l;
}
return;
}
if(d){
comp[x][d - 1] = (comp[x][d - 1] * w) % l;
}
comp[x][d] = (comp[x][d] * w) % l;
int to = pa[x];
solve(to, d - 1, w);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> l;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= 40; j++){
comp[i][j] = 1;
}
}
for(int i = 1; i < n; i++){
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
dfs(1, -1);
for(int i = 1; i <= n; i++)cin >> h[i];
int q; cin >> q;
while(q--){
int idq; cin >> idq;
if(idq == 1){
ll x, d, w; cin >> x >> d >> w;
solve(x, d, w);
}else{
int x; cin >> x;
int cnt = 0;
ll ans = h[x];
while(1){
ans = (ans * comp[x][cnt]) % mod;
x = pa[x]; cnt++;
if(cnt > 40 || x == -1)break;
}
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... |