This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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()) {
int64_t sum = -w[u];
while (iter != s[u].end() && iter->second + sum < 0) {
sum += iter->second;
iter = s[u].erase(iter);
}
if (iter != s[u].end()) {
iter->second += sum;
}
}
int v = p[u];
if (s[v].size() < s[u].size()) {
std::swap(s[v], s[u]);
}
for (auto [d, w] : s[u]) {
s[v][d] += w;
}
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |