이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 3;
const int cax = 42;
vector<int>g[nax];
int n;
long long L;
long long H[nax];
long long growth[nax][cax];
int par[nax];
void dfs(int v, int p = 1) {
par[v] = p;
for(int u : g[v]) if(u!=p) {
dfs(u, v);
}
}
void update(int v, int cd, int mt) {
if(cd<0) return;
growth[v][cd] = (growth[v][cd] * mt) % L;
if(v!=1) update(par[v], cd-1, mt);
}
long long query(int v, int cd) {
if(cd==cax) return 1LL;
long long ret = 1LL;
for(int j=cd; j<cax; ++j) {
if(j-1>=cd+1 && v!=1) continue;
ret = (ret * growth[v][j]) % L;
}
if(v!=1) ret = (ret * query(par[v], cd+1)) % L;
return ret;
}
void PlayGround() {
cin>>n>>L;
for(int i=0; i<n-1; ++i) {
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i=1; i<=n; ++i) {
cin>>H[i];
}
for(int i=1; i<=n; ++i) {
for(int j=0; j<cax; ++j) {
growth[i][j] = 1;
}
}
dfs(1);
int q;
cin>>q;
while(q--) {
int type;
cin>>type;
if(type==1) {
int x, d, w;
cin>>x>>d>>w;
update(x, d, w);
} else {
int x;
cin>>x;
long long ans = query(x, 0) * H[x];
ans %= L;
cout<<ans<<'\n';
}
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# | 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... |