Submission #994435

#TimeUsernameProblemLanguageResultExecution timeMemory
994435abczzWorst Reporter 4 (JOI21_worst_reporter4)C++14
14 / 100
2037 ms33316 KiB
#include <iostream> #include <queue> #define ll long long using namespace std; vector <ll> adj[200000]; ll n, f, x, A[200000], H[200000], C[200000], in[200000]; ll dp[200000]; ll dfs(ll u, ll w) { ll ret = 0, s = 0; if (w <= H[u]) ret = max(ret, dp[u]); for (auto v : adj[u]) { s += dfs(v, w); } return max(ret, s); } void solve(ll u) { for (auto v : adj[u]) { solve(v); } dp[u] = C[u]; for (auto v : adj[u]) { dp[u] += dfs(v, H[u]); } } int main() { cin >> n; for (int i=0; i<n; ++i) { cin >> A[i] >> H[i] >> C[i]; f += C[i]; --A[i]; if (i != A[i]) adj[A[i]].push_back(i); } solve(0); cout << f-dfs(0, 0) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...