Submission #796363

#TimeUsernameProblemLanguageResultExecution timeMemory
796363Dan4LifeWorst Reporter 4 (JOI21_worst_reporter4)C++17
0 / 100
231 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define sz(a) (int)a.size() #define all(a) begin(a),end(a) const int mxN = (int)2e5+10; const int LINF = (int)2e18; int n; unordered_map<int,int> dp[mxN]; int a[mxN], h[mxN], c[mxN]; vector<int> adj[mxN]; set<int> S[mxN]; int recur(int s, int v){ if(dp[s].count(v)) return dp[s][v]; int ans = (v!=h[s])*c[s]; S[s].insert(h[s]); for(auto u : adj[s]){ ans+=recur(u,v); if(sz(S[s])<sz(S[u])) S[s].swap(S[u]); for(auto u : S[u]) if(u>v) S[s].insert(u); } for(auto u : S[s]) ans = min(ans, recur(s,u)); return dp[s][v]=ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i] >> h[i] >> c[i]; if(i>1) adj[a[i]].pb(i); } cout << recur(1,*min_element(h+1,h+n+1)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...