Submission #1010196

#TimeUsernameProblemLanguageResultExecution timeMemory
1010196UnforgettableplWorst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
261 ms104272 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> C(n+1); int a;cin>>a>>H[1]>>C[1]; for(int i=2;i<=n;i++){ cin>>a>>H[i]>>C[i]; adj[a].emplace_back(i); } function<map<int,int>(int)> dfs = [&](int x){ map<int,int> DP; DP[0]=C[x]; DP[H[x]]=-C[x]; DP[H[x]+1]=C[x]; for(int&i:adj[x]){ auto curr = dfs(i); if(DP.size()<curr.size())swap(DP,curr); for(auto[a,b]:curr){ DP[a]+=b; if(DP[a]==0)DP.erase(a); } } auto iter = DP.find(H[x]); while(iter!=DP.end()){ if(iter->second>0)break; int val = iter->second; iter = DP.erase(iter);iter--; iter->second+=val; } 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...