Submission #966878

#TimeUsernameProblemLanguageResultExecution timeMemory
966878Trisanu_DasWorst Reporter 4 (JOI21_worst_reporter4)C++17
14 / 100
2007 ms39756 KiB
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define pb push_back #define int long long #define all(a) (a).begin(), (a).end() #define pii pair<int, int> const int N = 2e5 + 7; int n; int par[N], h[N], c[N]; vector<int> g[N]; long long dp[N], sum[N]; long long get(int node, int lim) { long long sol = c[node]; for (int v : g[node]) sol += get(v, lim); if (h[node] >= lim) sol = min(sol, dp[node]); return sol; } void dfs(int u) { sum[u] = c[u]; dp[u] = 0; for (int v : g[u]) { dfs(v); sum[u] += sum[v]; dp[u] += get(v, h[u]); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> par[i] >> h[i] >> c[i]; for (int i = 2; i <= n; ++i) g[par[i]].push_back(i); dfs(1); cout << get(1, 0); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...