Submission #796319

#TimeUsernameProblemLanguageResultExecution timeMemory
796319Dan4LifeWorst Reporter 4 (JOI21_worst_reporter4)C++17
14 / 100
418 ms399948 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define all(a) begin(a),end(a) const int mxN = (int)5e3+10; const int LINF = (int)2e18; int n, dp[mxN][mxN]; int a[mxN], h[mxN], c[mxN]; vector<int> adj[mxN]; int recur(int s, int v){ if(v>=5001) return LINF; if(dp[s][v]!=-1) return dp[s][v]; int ans = (v!=h[s])*c[s]; for(auto u : adj[s]) ans+=recur(u,v); ans = min(ans, recur(s,v+1)); return dp[s][v]=ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; vector<int> v; memset(dp,-1,sizeof(dp)); for(int i = 1; i <= n; i++){ cin >> a[i] >> h[i] >> c[i]; if(i>1) adj[a[i]].pb(i); v.pb(h[i]); } sort(all(v)); v.erase(unique(all(v)),end(v)); for(int i = 1; i <= n; i++) h[i]=lower_bound(all(v),h[i])-begin(v); cout << recur(1,0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...