이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int maxn = 200000;
vector<int> v[maxn];
int p[maxn];
int ml[maxn][41];
inline void dfs(int nd, int ss){
p[nd] = ss;
for(int x: v[nd]) if(x != ss) dfs(x, nd);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, md; cin >> n >> md;
for(int i = 0; i < n; i++) for(int j = 0; j <= 40; j++) ml[i][j] = 1;
for(int i = 0; i < n-1; i++){
int a, b; cin >> a >> b; a--, b--;
v[a].pb(b);
v[b].pb(a);
}
for(int i = 0; i < n; i++) cin >> ml[i][0];
dfs(0, -1);
int q; cin >> q;
while(q--){
int tt; cin >> tt;
if(tt == 1){
int nd, d, w; cin >> nd >> d >> w; nd--;
while(d >= 0){
ml[nd][d]=(ll(ml[nd][d])*w)%md;
if(d != 0) ml[nd][d-1]=(ll(ml[nd][d-1])*w)%md;
if(p[nd] == -1){
for(int i = 0; i < d-1; i++) ml[nd][i]=(ll(ml[nd][i])*w)%md;
break;
}
d--;
nd = p[nd];
}
}
else{
int nd; cin >> nd; nd--;
int d = 0;
int ans = 1;
while(d <= 40){
ans=(ll(ans)*ml[nd][d])%md;
nd = p[nd];
d++;
if(nd == -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... |