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 int64_t
const int Z = 2e5+1, B = 42;
int N, L, H[Z][B], W, res;
#define mul(VL) if((VL *= W) >= L) VL %= L
int p[Z];
vector<int> g[Z];
void dfs(int u) {
for(const int &v : g[u]) if(v != p[u])
p[v] = u, dfs(v);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> L;
for(int i = 1; i < N; ++i) {
int u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
for(int i = 0; i <= N; ++i)
fill(H[i], H[i] + B, 1);
for(int i = 1; i <= N; ++i)
cin >> H[i][0];
int Q, T, u, d; cin >> Q;
for(int i = 1; i <= Q; ++i) {
cin >> T >> u;
if(T & 1) {
cin >> d >> W;
while(u) {
mul(H[u][d]);
if(d) {
mul(H[u][d-1]);
--d;
u = p[u];
} else break;
}
if(!u) {
while(d) {
mul(H[0][d]);
--d;
}
}
} else {
res = H[u][0];
u = p[u];
for(d = 1; d < B; ++d) {
(res *= H[u][d]) %= L;
if(!u) break;
u = p[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... |