제출 #1256510

#제출 시각아이디문제언어결과실행 시간메모리
1256510LucaLucaMWorst Reporter 4 (JOI21_worst_reporter4)C++20
0 / 100
2 ms1348 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <map> using ll = long long; #define debug(x) #x << " = " << x << '\n' void merge(std::map<int, ll> &a, const std::map<int, ll> &b) { for (auto &[h, v] : a) { ll best = 0; for (const auto &[x, y] : b) { if (x <= h) { best = std::max(best, y); } } v += best; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n; std::cin >> n; std::vector<int> h(n), c(n); std::vector<std::vector<int>> g(n); ll answer = 0; for (int i = 0; i < n; i++) { int p; std::cin >> p >> h[i] >> c[i]; h[i] *= -1; p--; answer += c[i]; if (p != i) { g[p].push_back(i); } } std::vector<std::map<int, ll>> dp(n); auto dfs = [&](auto &&self, int u) -> void { dp[u][0] = 0; dp[u][h[u]] = c[u]; for (int v : g[u]) { self(self, v); merge(dp[u], dp[v]); } }; dfs(dfs, 0); ll maxi = 0; for (const auto &[x, y] : dp[0]) { maxi = std::max(maxi, y); } answer -= maxi; std::cout << answer; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...