#include <bits/stdc++.h>
using namespace std;
#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const lg N = 1e5+5;
lg n, m, k;
lg v[N], d[N];
vector<lg> adj[N];
map<lg, lg> mp2;
void solve(lg src)
{
map<lg, lg> mp;
for(auto it : adj[src])
{
solve(it);
if(mp.size() < mp2.size())
{
swap(mp, mp2);
}
for(auto [it, fr] : mp2)
{
mp[it] += fr;
}
}
if(d[src])
{
mp[d[src]] += v[src];
while(true)
{
auto it = mp.upper_bound(d[src]);
if(it == mp.end()) break;
if(it->second <= v[src])
{
v[src] -= it->second;
mp.erase(it);
continue;
}
it->second -= v[src];
break;
}
}
swap(mp, mp2);
return ;
}
int main()
{
fastio;
cin >> n >> m >> k;
for(int i = 2; i <= n; i++)
{
lg p;
cin >> p;
adj[p].push_back(i);
}
for(int i = 1; i <= m; i++)
{
lg node, day, score;
cin >> node >> day >> score;
d[node] = day;
v[node] = score;
}
solve(1);
lg ans = 0;
for(auto [a, b] : mp2) ans += b;
cout << ans << '\n';
return 0;
}
/*
dp[src][max] = max(dp[par][v[i]]+w[i], dp[src][max-1])
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
8036 KB |
Output is correct |
2 |
Correct |
28 ms |
14172 KB |
Output is correct |
3 |
Correct |
76 ms |
10292 KB |
Output is correct |
4 |
Correct |
57 ms |
8684 KB |
Output is correct |
5 |
Correct |
61 ms |
11096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2820 KB |
Output is correct |
4 |
Correct |
41 ms |
26552 KB |
Output is correct |
5 |
Correct |
58 ms |
30548 KB |
Output is correct |
6 |
Correct |
69 ms |
26452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
6232 KB |
Output is correct |
2 |
Correct |
32 ms |
6236 KB |
Output is correct |
3 |
Correct |
35 ms |
13648 KB |
Output is correct |
4 |
Correct |
24 ms |
5080 KB |
Output is correct |
5 |
Correct |
44 ms |
24648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
37 ms |
6248 KB |
Output is correct |
11 |
Correct |
37 ms |
7508 KB |
Output is correct |
12 |
Correct |
35 ms |
15212 KB |
Output is correct |
13 |
Correct |
24 ms |
6276 KB |
Output is correct |
14 |
Correct |
41 ms |
26192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3420 KB |
Output is correct |
2 |
Correct |
16 ms |
6272 KB |
Output is correct |
3 |
Correct |
17 ms |
6036 KB |
Output is correct |
4 |
Correct |
21 ms |
6236 KB |
Output is correct |
5 |
Correct |
7 ms |
5080 KB |
Output is correct |
6 |
Correct |
16 ms |
9564 KB |
Output is correct |
7 |
Correct |
23 ms |
14428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2820 KB |
Output is correct |
13 |
Correct |
41 ms |
26552 KB |
Output is correct |
14 |
Correct |
58 ms |
30548 KB |
Output is correct |
15 |
Correct |
69 ms |
26452 KB |
Output is correct |
16 |
Correct |
37 ms |
6248 KB |
Output is correct |
17 |
Correct |
37 ms |
7508 KB |
Output is correct |
18 |
Correct |
35 ms |
15212 KB |
Output is correct |
19 |
Correct |
24 ms |
6276 KB |
Output is correct |
20 |
Correct |
41 ms |
26192 KB |
Output is correct |
21 |
Correct |
13 ms |
3932 KB |
Output is correct |
22 |
Correct |
38 ms |
7808 KB |
Output is correct |
23 |
Correct |
45 ms |
9548 KB |
Output is correct |
24 |
Correct |
70 ms |
11288 KB |
Output is correct |
25 |
Correct |
43 ms |
10188 KB |
Output is correct |
26 |
Correct |
59 ms |
15088 KB |
Output is correct |
27 |
Correct |
63 ms |
17264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
34 ms |
8036 KB |
Output is correct |
11 |
Correct |
28 ms |
14172 KB |
Output is correct |
12 |
Correct |
76 ms |
10292 KB |
Output is correct |
13 |
Correct |
57 ms |
8684 KB |
Output is correct |
14 |
Correct |
61 ms |
11096 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
2820 KB |
Output is correct |
18 |
Correct |
41 ms |
26552 KB |
Output is correct |
19 |
Correct |
58 ms |
30548 KB |
Output is correct |
20 |
Correct |
69 ms |
26452 KB |
Output is correct |
21 |
Correct |
34 ms |
6232 KB |
Output is correct |
22 |
Correct |
32 ms |
6236 KB |
Output is correct |
23 |
Correct |
35 ms |
13648 KB |
Output is correct |
24 |
Correct |
24 ms |
5080 KB |
Output is correct |
25 |
Correct |
44 ms |
24648 KB |
Output is correct |
26 |
Correct |
37 ms |
6248 KB |
Output is correct |
27 |
Correct |
37 ms |
7508 KB |
Output is correct |
28 |
Correct |
35 ms |
15212 KB |
Output is correct |
29 |
Correct |
24 ms |
6276 KB |
Output is correct |
30 |
Correct |
41 ms |
26192 KB |
Output is correct |
31 |
Correct |
4 ms |
3420 KB |
Output is correct |
32 |
Correct |
16 ms |
6272 KB |
Output is correct |
33 |
Correct |
17 ms |
6036 KB |
Output is correct |
34 |
Correct |
21 ms |
6236 KB |
Output is correct |
35 |
Correct |
7 ms |
5080 KB |
Output is correct |
36 |
Correct |
16 ms |
9564 KB |
Output is correct |
37 |
Correct |
23 ms |
14428 KB |
Output is correct |
38 |
Correct |
13 ms |
3932 KB |
Output is correct |
39 |
Correct |
38 ms |
7808 KB |
Output is correct |
40 |
Correct |
45 ms |
9548 KB |
Output is correct |
41 |
Correct |
70 ms |
11288 KB |
Output is correct |
42 |
Correct |
43 ms |
10188 KB |
Output is correct |
43 |
Correct |
59 ms |
15088 KB |
Output is correct |
44 |
Correct |
63 ms |
17264 KB |
Output is correct |
45 |
Correct |
12 ms |
4188 KB |
Output is correct |
46 |
Correct |
43 ms |
7896 KB |
Output is correct |
47 |
Correct |
50 ms |
9956 KB |
Output is correct |
48 |
Correct |
77 ms |
12360 KB |
Output is correct |
49 |
Correct |
46 ms |
10956 KB |
Output is correct |
50 |
Correct |
69 ms |
16524 KB |
Output is correct |
51 |
Correct |
60 ms |
18000 KB |
Output is correct |