This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |