Submission #514961

# Submission time Handle Problem Language Result Execution time Memory
514961 2022-01-18T23:24:13 Z CrouchingDragon Magic Tree (CEOI19_magictree) C++17
0 / 100
57 ms 18784 KB
#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;
    }
  }
  std::cout << s[0].rbegin()->second << '\n';
  exit(0);
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 18784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 10700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -