제출 #514953

#제출 시각아이디문제언어결과실행 시간메모리
514953CrouchingDragonMagic Tree (CEOI19_magictree)C++17
3 / 100
123 ms37848 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...