#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
#define ll long long
ll n, u, v, q, l, h[nx], lz1[nx], lz2[nx], pa[nx], t, x, ds, w;
vector<ll> d[nx];
void dfs(int u, int p)
{
pa[u]=p;
for (auto v:d[u]) if (v!=p) dfs(v, u);
}
void update(int u, ll w)
{
h[u]=(h[u]*w)%l;
if (pa[u]!=u) h[pa[u]]=(h[pa[u]]*w)%l;
lz1[u]=(lz1[u]*w)%l;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>l;
for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
for (int i=1; i<=n; i++) cin>>h[i], lz1[i]=1, lz2[i]=1;
dfs(1, 1);
cin>>q;
while (q--)
{
cin>>t;
if (t==1)
{
cin>>x>>ds>>w;
if (ds==0) h[x]=(h[x]*w)%l;
else if (ds==1) update(x, w);
else
{
if (pa[x]!=x) update(pa[x], w);
else h[x]=(h[x]*w)%l;
lz1[x]=(lz1[x]*w)%l;
lz2[x]=(lz2[x]*w)%l;
}
}
else
{
cin>>u;
ll res=h[u];
if (pa[u]!=u)
{
res=(res*lz1[pa[u]])%l;
if (pa[pa[u]]!=pa[u]) res=(res*lz2[pa[pa[u]]])%l;
}
cout<<res<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
10840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
164 ms |
30344 KB |
Output is correct |
3 |
Correct |
195 ms |
30512 KB |
Output is correct |
4 |
Correct |
147 ms |
32600 KB |
Output is correct |
5 |
Correct |
156 ms |
30544 KB |
Output is correct |
6 |
Correct |
151 ms |
30036 KB |
Output is correct |
7 |
Correct |
147 ms |
31060 KB |
Output is correct |
8 |
Correct |
132 ms |
31036 KB |
Output is correct |
9 |
Correct |
183 ms |
34128 KB |
Output is correct |
10 |
Correct |
159 ms |
34132 KB |
Output is correct |
11 |
Correct |
153 ms |
30540 KB |
Output is correct |
12 |
Correct |
155 ms |
30544 KB |
Output is correct |
13 |
Correct |
135 ms |
30908 KB |
Output is correct |
14 |
Correct |
127 ms |
30908 KB |
Output is correct |
15 |
Correct |
141 ms |
29820 KB |
Output is correct |
16 |
Correct |
133 ms |
30112 KB |
Output is correct |
17 |
Correct |
132 ms |
30544 KB |
Output is correct |
18 |
Correct |
2 ms |
10840 KB |
Output is correct |
19 |
Correct |
1 ms |
10844 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
164 ms |
30344 KB |
Output is correct |
3 |
Correct |
195 ms |
30512 KB |
Output is correct |
4 |
Correct |
147 ms |
32600 KB |
Output is correct |
5 |
Correct |
156 ms |
30544 KB |
Output is correct |
6 |
Correct |
151 ms |
30036 KB |
Output is correct |
7 |
Correct |
147 ms |
31060 KB |
Output is correct |
8 |
Correct |
132 ms |
31036 KB |
Output is correct |
9 |
Correct |
183 ms |
34128 KB |
Output is correct |
10 |
Correct |
159 ms |
34132 KB |
Output is correct |
11 |
Correct |
153 ms |
30540 KB |
Output is correct |
12 |
Correct |
155 ms |
30544 KB |
Output is correct |
13 |
Correct |
135 ms |
30908 KB |
Output is correct |
14 |
Correct |
127 ms |
30908 KB |
Output is correct |
15 |
Correct |
141 ms |
29820 KB |
Output is correct |
16 |
Correct |
133 ms |
30112 KB |
Output is correct |
17 |
Correct |
132 ms |
30544 KB |
Output is correct |
18 |
Correct |
2 ms |
10840 KB |
Output is correct |
19 |
Correct |
1 ms |
10844 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
1 ms |
10844 KB |
Output is correct |
24 |
Correct |
150 ms |
29848 KB |
Output is correct |
25 |
Correct |
166 ms |
31056 KB |
Output is correct |
26 |
Correct |
154 ms |
34384 KB |
Output is correct |
27 |
Correct |
146 ms |
30532 KB |
Output is correct |
28 |
Correct |
141 ms |
30772 KB |
Output is correct |
29 |
Correct |
145 ms |
20868 KB |
Output is correct |
30 |
Correct |
112 ms |
29368 KB |
Output is correct |
31 |
Correct |
133 ms |
31824 KB |
Output is correct |
32 |
Correct |
158 ms |
32344 KB |
Output is correct |
33 |
Correct |
146 ms |
25220 KB |
Output is correct |
34 |
Correct |
136 ms |
19404 KB |
Output is correct |
35 |
Correct |
2 ms |
10840 KB |
Output is correct |
36 |
Correct |
1 ms |
10844 KB |
Output is correct |
37 |
Correct |
2 ms |
10912 KB |
Output is correct |
38 |
Correct |
3 ms |
10844 KB |
Output is correct |
39 |
Correct |
2 ms |
10844 KB |
Output is correct |
40 |
Correct |
1 ms |
10844 KB |
Output is correct |
41 |
Correct |
1 ms |
10844 KB |
Output is correct |
42 |
Correct |
1 ms |
10844 KB |
Output is correct |
43 |
Correct |
1 ms |
10844 KB |
Output is correct |
44 |
Correct |
2 ms |
10840 KB |
Output is correct |
45 |
Correct |
2 ms |
10840 KB |
Output is correct |
46 |
Correct |
2 ms |
10844 KB |
Output is correct |
47 |
Correct |
2 ms |
10844 KB |
Output is correct |
48 |
Correct |
2 ms |
10840 KB |
Output is correct |
49 |
Correct |
1 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10844 KB |
Output is correct |
2 |
Incorrect |
145 ms |
25220 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
10844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
10840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |