Submission #514952

#TimeUsernameProblemLanguageResultExecution timeMemory
514952CrouchingDragonMagic Tree (CEOI19_magictree)C++17
3 / 100
147 ms40260 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]); } 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 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...