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>
using namespace std;
#define int long long
#define vec vector
#define arr array
const int MXN = 200'005;
const int MXD = 43;
int pars[MXN];
vec<int> tree[MXN];
void dfs0(int u = 0, int p = -1) {
pars[u] = p;
for(int v : tree[u]) {
if(v == p) continue;
dfs0(v, u);
}
}
int32_t main() {
int N, L;
cin >> N >> L;
for(int i = 0; i<N-1; i++) {
int u, v;
cin >> u >> v;
u--,v--;
tree[u].push_back(v);
tree[v].push_back(u);
}
dfs0();
vec<vec<int>> contr(N, vec<int>(MXD+1, 1));
for(int i = 0; i<N; i++) {
int h;
cin >> h;
contr[i][0] = h;
}
int Q;
cin >> Q;
while(Q--) {
int t, u;
cin >> t >> u;
u--;
if(t==1) {
int d, m;
cin >> d >> m;
while(u != -1 && d >= 0) {
//cerr <<"UPD: " << u << '\n';
contr[u][d] *= m;
contr[u][d] %= L;
u = pars[u];
d--;
}
//cerr <<"----------" << '\n';
if(false){
for(int i = 0; i<N; i++) {
for(int j = 0; j<5; j++) {
cerr << contr[i][j] << ' ';
}
cerr << '\n';
}
cerr << '\n';
}
//cerr << "------------------" << '\n';
}
else {
assert(t==2);
int res = 1;
for(int i = 0; i<MXD && u != -1; i++) {
for(int j = i; j<((pars[u] == -1) ? (MXD+1) : (i+2)); j++) {
res *= contr[u][j];
res %= L;
//cerr << "MUL: " << res << '\n';
}
u = pars[u];
}
cout << res << '\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... |