#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
const int MAXN = 2e5+5;
int MOD;
vector<int>adj[MAXN];
int par[MAXN],h[MAXN],m[41][MAXN];
int mult(int a,int b)
{
return (a*1LL*b)%MOD;
}
void dfs(int v,int u){
par[v] = u;
for(int x:adj[v]){
if(x!=u)dfs(x,v);
}
}
int main()
{
owo
int n;
cin>>n>>MOD;
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(1,0);
for(int i=1;i<=n;i++){
cin>>h[i];
for(int j=0;j<=40;j++)m[j][i] = 1;
}
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==2){
int v;
cin>>v;
int ans = h[v];
int d = 0;
while(v){
ans = mult(ans,m[d][v]);
v = par[v];
d++;
}
cout<<ans<<'\n';
}else{
int x,k,w;
cin>>x>>k>>w;
while(x!=1 && k>=0){
m[k][x] = mult(m[k][x],w);
if(k)m[k-1][x] = mult(m[k-1][x],w);
k--;
x = par[x];
}
if(k>=0){
for(int j=0;j<=k;j++)m[j][1] = mult(m[j][1],w);
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Runtime error |
9 ms |
10796 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Runtime error |
167 ms |
95580 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Runtime error |
167 ms |
95580 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Runtime error |
207 ms |
104148 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Runtime error |
178 ms |
101244 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Runtime error |
9 ms |
10796 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |