Submission #1010152

#TimeUsernameProblemLanguageResultExecution timeMemory
1010152UnforgettableplWorst Reporter 4 (JOI21_worst_reporter4)C++17
14 / 100
2048 ms197088 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> adj(n+1); vector<int> H(n+1); vector<int> Hs(n+1); vector<int> C(n+1); int a;cin>>a>>H[1]>>C[1];Hs[1]=H[1]; for(int i=2;i<=n;i++){ cin>>a>>H[i]>>C[i];Hs[i]=H[i]; adj[a].emplace_back(i); } sort(Hs.begin(),Hs.end()); Hs.erase(unique(Hs.begin(),Hs.end()),Hs.end()); int k = Hs.size(); function<vector<int>(int)> dfs = [&](int x){ vector<int> DP(k); for(int i=0;i<k;i++)if(Hs[i]!=H[x])DP[i]=C[x]; for(int&i:adj[x]){ auto curr = dfs(i); for(int j=0;j<k;j++)DP[j]+=curr[j]; } for(int i=k-2;i>=0;i--)DP[i]=min(DP[i],DP[i+1]); return DP; }; cout << dfs(1)[0] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...