이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
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);
}
int 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... |