Submission #1051321

#TimeUsernameProblemLanguageResultExecution timeMemory
1051321deeraJobs (BOI24_jobs)C++14
0 / 100
53 ms29776 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> profit;
vector<set<int>> children;

int profit_dp(int node) {
    // childrens_profit = sum of positive profits of children
    // return max(profit[node] + childrens_profit, 0)

    int cp = 0;
    for(auto child : children[node]) {
        cp += max(profit_dp(child), 0);
    }

    return max(profit[node] + cp, 0);
}

int main() {
    int n, s;
    cin >> n >> s;

    profit.resize(n+1);
    children.resize(n+1);

    
    for(int i = 0 ; i < n; i++) {
        int 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...