#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5 + 5;
ll n, l, q, val[MAXN];
vector<ll> adjl[MAXN];
bool visited[MAXN];
void update(ll now, ll kurang, ll weight) {
val[now] *= weight % l;
val[now] %= l;
if (kurang == 0)
{
return ;
}
visited[now] = true;
vector<ll> adjn = adjl[now];
for (int i = 0; i < adjn.size(); ++i)
{
ll nxt = adjn[i];
if (visited[nxt])
{
continue ;
}
update(nxt, kurang-1, weight);
}
visited[now] = false;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> l;
for (int i = 1; i <= n-1; ++i)
{
ll tmpa, tmpb;
cin >> tmpa >> tmpb;
adjl[tmpa].push_back(tmpb);
adjl[tmpb].push_back(tmpa);
}
for (int i = 1; i <= n; ++i)
{
cin >> val[i];
}
cin >> q;
while(q--) {
ll type;
cin >> type;
if (type == 1) {
ll x, d, w;
cin >> x >> d >> w;
update(x, d, w);
} else {
ll x;
cin >> x;
cout << val[x] << "\n";
}
}
return 0;
}
Compilation message
sprinkler.cpp: In function 'void update(ll, ll, ll)':
sprinkler.cpp:21:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < adjn.size(); ++i)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
6 ms |
5084 KB |
Output is correct |
6 |
Correct |
12 ms |
5084 KB |
Output is correct |
7 |
Correct |
17 ms |
5084 KB |
Output is correct |
8 |
Correct |
10 ms |
5076 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4972 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 |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
2 ms |
4948 KB |
Output is correct |
26 |
Correct |
2 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
154 ms |
17584 KB |
Output is correct |
3 |
Correct |
286 ms |
14412 KB |
Output is correct |
4 |
Correct |
178 ms |
14848 KB |
Output is correct |
5 |
Correct |
185 ms |
15948 KB |
Output is correct |
6 |
Correct |
219 ms |
16044 KB |
Output is correct |
7 |
Correct |
196 ms |
16412 KB |
Output is correct |
8 |
Correct |
165 ms |
16584 KB |
Output is correct |
9 |
Correct |
252 ms |
16352 KB |
Output is correct |
10 |
Correct |
249 ms |
13312 KB |
Output is correct |
11 |
Correct |
192 ms |
17552 KB |
Output is correct |
12 |
Correct |
235 ms |
14436 KB |
Output is correct |
13 |
Execution timed out |
4066 ms |
15860 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
154 ms |
17584 KB |
Output is correct |
3 |
Correct |
286 ms |
14412 KB |
Output is correct |
4 |
Correct |
178 ms |
14848 KB |
Output is correct |
5 |
Correct |
185 ms |
15948 KB |
Output is correct |
6 |
Correct |
219 ms |
16044 KB |
Output is correct |
7 |
Correct |
196 ms |
16412 KB |
Output is correct |
8 |
Correct |
165 ms |
16584 KB |
Output is correct |
9 |
Correct |
252 ms |
16352 KB |
Output is correct |
10 |
Correct |
249 ms |
13312 KB |
Output is correct |
11 |
Correct |
192 ms |
17552 KB |
Output is correct |
12 |
Correct |
235 ms |
14436 KB |
Output is correct |
13 |
Execution timed out |
4066 ms |
15860 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
433 ms |
13840 KB |
Output is correct |
3 |
Correct |
2521 ms |
13044 KB |
Output is correct |
4 |
Correct |
849 ms |
13448 KB |
Output is correct |
5 |
Execution timed out |
4078 ms |
14368 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
482 ms |
16528 KB |
Output is correct |
3 |
Correct |
2626 ms |
13388 KB |
Output is correct |
4 |
Correct |
901 ms |
14888 KB |
Output is correct |
5 |
Execution timed out |
4080 ms |
15368 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
6 ms |
5084 KB |
Output is correct |
6 |
Correct |
12 ms |
5084 KB |
Output is correct |
7 |
Correct |
17 ms |
5084 KB |
Output is correct |
8 |
Correct |
10 ms |
5076 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4972 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 |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
2 ms |
4948 KB |
Output is correct |
26 |
Correct |
2 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
2 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
154 ms |
17584 KB |
Output is correct |
31 |
Correct |
286 ms |
14412 KB |
Output is correct |
32 |
Correct |
178 ms |
14848 KB |
Output is correct |
33 |
Correct |
185 ms |
15948 KB |
Output is correct |
34 |
Correct |
219 ms |
16044 KB |
Output is correct |
35 |
Correct |
196 ms |
16412 KB |
Output is correct |
36 |
Correct |
165 ms |
16584 KB |
Output is correct |
37 |
Correct |
252 ms |
16352 KB |
Output is correct |
38 |
Correct |
249 ms |
13312 KB |
Output is correct |
39 |
Correct |
192 ms |
17552 KB |
Output is correct |
40 |
Correct |
235 ms |
14436 KB |
Output is correct |
41 |
Execution timed out |
4066 ms |
15860 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |