Submission #1035288

#TimeUsernameProblemLanguageResultExecution timeMemory
1035288AndreyJobs (BOI24_jobs)C++14
58 / 100
2044 ms72020 KiB
#include<bits/stdc++.h> using namespace std; vector<long long> haha[400001]; vector<long long> c(400001); vector<long long> dp(400001); void dfs(long long a) { for(long long v: haha[a]) { dfs(v); } long long br = 0; priority_queue<pair<long long,long long>> idk; idk.push({-c[a],a}); while(!idk.empty()) { pair<long long,long long> b = idk.top(); idk.pop(); br+=c[b.second]; if(br > 0) { break; } dp[a] = max(dp[a],-br); for(long long v: haha[b.second]) { idk.push({-dp[v],v}); } } if(br <= 0) { dp[a] = LLONG_MAX; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,s,p; cin >> n >> s; for(long long i = 1; i <= n; i++) { cin >> c[i] >> p; haha[p].push_back(i); } dfs(0); long long ans = s,br = s; priority_queue<pair<long long,long long>> idk; idk.push({-dp[0],0}); while(!idk.empty()) { pair<long long,long long> b = idk.top(); idk.pop(); if(b.first > br) { break; } br+=c[b.second]; ans = max(ans,br); for(long long v: haha[b.second]) { idk.push({-dp[v],v}); } } cout << ans-s; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...