#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,l;
ll p[maxN],h[maxN];
ll q;
vector<ll>g[maxN];
void dfs(ll u,ll P=0)
{
p[u]=P;
for(int v:g[u])
{
if(v!=P) dfs(v,u);
}
}
ll lazy[maxN][42];
void solve()
{
cin >> n >> l;
for(int i=1;i<n;i++)
{
ll u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int i=1;i<=n;i++) cin >> h[i];
cin >> q;
for(int i=1;i<=n;i++) for(int j=0;j<=41;j++) lazy[i][j]=1;
dfs(1);
while(q--)
{
ll t;
cin >> t;
if(t==1)
{
ll u,d,w;
cin >> u >> d >> w;
ll x=u;
for(int i=0;i<=d;i++)
{
ll &k=lazy[x][d-i];
k=k*w%l;
if(x!=1&&d-i>0)
{
lazy[x][d-i-1]=lazy[x][d-i-1]*w%l;
}
if(p[x]!=0) x=p[x];
}
}
else
{
ll u;
cin >> u;
ll ans=h[u];
for(int i=0;i<=41;i++)
{
ans=ans*lazy[u][i]%mod;
if(p[u]==0) break;
else u=p[u];
}
cout << ans<<'\n';
}
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
4 ms |
5036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Correct |
753 ms |
93892 KB |
Output is correct |
3 |
Correct |
814 ms |
93496 KB |
Output is correct |
4 |
Correct |
625 ms |
93236 KB |
Output is correct |
5 |
Correct |
508 ms |
90268 KB |
Output is correct |
6 |
Correct |
321 ms |
90436 KB |
Output is correct |
7 |
Correct |
286 ms |
90620 KB |
Output is correct |
8 |
Correct |
227 ms |
90836 KB |
Output is correct |
9 |
Correct |
743 ms |
92496 KB |
Output is correct |
10 |
Correct |
712 ms |
93964 KB |
Output is correct |
11 |
Correct |
520 ms |
89852 KB |
Output is correct |
12 |
Correct |
528 ms |
90908 KB |
Output is correct |
13 |
Correct |
349 ms |
91640 KB |
Output is correct |
14 |
Correct |
402 ms |
92540 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
5040 KB |
Output is correct |
19 |
Correct |
3 ms |
5040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Incorrect |
746 ms |
94948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
4 ms |
5036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |