Submission #1051328

#TimeUsernameProblemLanguageResultExecution timeMemory
1051328deeraJobs (BOI24_jobs)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> profit; vector<set<ll>> children; ll profit_dp(ll node) { // childrens_profit = sum of positive profits of children // return max(profit[node] + childrens_profit, 0) ll cp = 0; for(auto child : children[node]) { cp += max(profit_dp(child), 0ll); } return max(profit[node] + cp, 0ll); } int main() { ll n, s; cin >> n >> s; if (s == 10e18) { profit.resize(n+1); children.resize(n+1); for(ll i = 0 ; i < n; i++) { ll x, p; cin >> x >> p; profit[i+1] = x; children[p].insert(i+1); } cout << profit_dp(0) << endl; 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...