#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
const int N = 2e5;
long long h[N+5];
int n, l;
vector<int> adj[N+5];
void dfs (int u, int prv, long long w, int dst) {
if (dst < 0) return;
h[u] *= w;
h[u] %= l;
//cerr << u << " lalala " << h[u] << endl;
for (int v : adj[u]) {
if (v==prv) continue;
dfs(v, u, w, dst-1);
}
}
void solve() {
cin >> n >> l;
for(int i=1; i<n; i++) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
for (int i=1; i<=n; i++) {
cin >> h[i];
}
int q;
cin >> q;
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int x, d, w;
cin >> x >> d >> w;
dfs(x, 0, w, d);
} else {
int x;
cin >> x;
cout << h[x] << endl;
}
}
}
signed main () {
int t=1;
//scanf("%d", &t);
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5008 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
5 ms |
5076 KB |
Output is correct |
6 |
Correct |
11 ms |
5076 KB |
Output is correct |
7 |
Correct |
12 ms |
5076 KB |
Output is correct |
8 |
Correct |
8 ms |
4980 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
5 ms |
5008 KB |
Output is correct |
12 |
Correct |
5 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5012 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
5020 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
8 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4984 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4936 KB |
Output is correct |
26 |
Correct |
4 ms |
5008 KB |
Output is correct |
27 |
Correct |
4 ms |
5004 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
830 ms |
16524 KB |
Output is correct |
3 |
Correct |
597 ms |
13376 KB |
Output is correct |
4 |
Correct |
715 ms |
14744 KB |
Output is correct |
5 |
Correct |
695 ms |
14956 KB |
Output is correct |
6 |
Correct |
748 ms |
14708 KB |
Output is correct |
7 |
Correct |
758 ms |
15116 KB |
Output is correct |
8 |
Execution timed out |
4059 ms |
13752 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
830 ms |
16524 KB |
Output is correct |
3 |
Correct |
597 ms |
13376 KB |
Output is correct |
4 |
Correct |
715 ms |
14744 KB |
Output is correct |
5 |
Correct |
695 ms |
14956 KB |
Output is correct |
6 |
Correct |
748 ms |
14708 KB |
Output is correct |
7 |
Correct |
758 ms |
15116 KB |
Output is correct |
8 |
Execution timed out |
4059 ms |
13752 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1286 ms |
13688 KB |
Output is correct |
3 |
Execution timed out |
4017 ms |
12980 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1070 ms |
16308 KB |
Output is correct |
3 |
Correct |
3354 ms |
13180 KB |
Output is correct |
4 |
Correct |
1322 ms |
14636 KB |
Output is correct |
5 |
Execution timed out |
4058 ms |
14520 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5008 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
5 ms |
5076 KB |
Output is correct |
6 |
Correct |
11 ms |
5076 KB |
Output is correct |
7 |
Correct |
12 ms |
5076 KB |
Output is correct |
8 |
Correct |
8 ms |
4980 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
5 ms |
5008 KB |
Output is correct |
12 |
Correct |
5 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5012 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
5020 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
8 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4984 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4936 KB |
Output is correct |
26 |
Correct |
4 ms |
5008 KB |
Output is correct |
27 |
Correct |
4 ms |
5004 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
830 ms |
16524 KB |
Output is correct |
31 |
Correct |
597 ms |
13376 KB |
Output is correct |
32 |
Correct |
715 ms |
14744 KB |
Output is correct |
33 |
Correct |
695 ms |
14956 KB |
Output is correct |
34 |
Correct |
748 ms |
14708 KB |
Output is correct |
35 |
Correct |
758 ms |
15116 KB |
Output is correct |
36 |
Execution timed out |
4059 ms |
13752 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |