#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M, K;
std::cin >> N >> M >> K;
std::vector<int> p(N);
for (int u = 1; u < N; ++u) {
std::cin >> p[u];
--p[u];
}
std::vector<int> d(N), w(N);
for (int j = 0; j < M; ++j) {
int v;
std::cin >> v;
--v;
std::cin >> d[v] >> w[v];
}
std::vector<std::map<int, int64_t>> s(N);
for (int u = N - 1; u > 0; --u) {
auto iter = s[u].insert({d[u], 0}).first;
iter->second += w[u];
++iter;
if (iter != s[u].end()) {
iter->second -= w[u];
}
int v = p[u];
if (s[v].size() < s[u].size()) {
std::swap(s[v], s[u]);
}
int64_t last = 0, maxpref = 0, pref = 0;
for (auto [d, w] : s[u]) {
pref += w;
maxpref = std::max(maxpref, pref);
s[v][d] += maxpref - last;
last = maxpref;
}
}
int64_t maxpref = 0, pref = 0;
for (auto [d, w] : s[0]) {
pref += w;
maxpref = std::max(maxpref, pref);
}
std::cout << maxpref << '\n';
exit(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
18796 KB |
Output is correct |
2 |
Correct |
26 ms |
9292 KB |
Output is correct |
3 |
Correct |
123 ms |
37848 KB |
Output is correct |
4 |
Correct |
66 ms |
16040 KB |
Output is correct |
5 |
Correct |
82 ms |
20440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
10856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |