Submission #897326

#TimeUsernameProblemLanguageResultExecution timeMemory
897326juliany2Worst Reporter 4 (JOI21_worst_reporter4)C++17
14 / 100
74 ms197204 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() const int N = 5007; int n; int h[N], c[N]; vector<int> adj[N]; ll dp[N][N]; void dfs(int v = 1) { for (int u : adj[v]) { dfs(u); for (int i = 1; i <= n; i++) dp[v][i] += dp[u][i]; } for (int i = 1; i <= h[v]; i++) dp[v][i] = max(dp[v][i], dp[v][h[v]] + c[v]); } int main() { cin.tie(0)->sync_with_stdio(false); cin >> n; ll sum = 0; vector<int> cmp = {0}; for (int i = 1; i <= n; i++) { int p; cin >> p >> h[i] >> c[i]; if (i != 1) adj[p].push_back(i); cmp.push_back(h[i]); sum += c[i]; } sort(all(cmp)); cmp.erase(unique(all(cmp)), cmp.end()); for (int i = 1; i <= n; i++) h[i] = lower_bound(all(cmp), h[i]) - cmp.begin(); dfs(); cout << sum - *max_element(dp[1] + 1, dp[1] + n + 1) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...