Submission #1235995

#TimeUsernameProblemLanguageResultExecution timeMemory
1235995dssfsuper2Magic Tree (CEOI19_magictree)C++20
6 / 100
2096 ms4936 KiB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define all(x) (x).begin(), (x).end()


vector<int> values;
vector<int> days;
vector<vector<int>> adj;
int dpf(int node, int limd){
    int res = (days[node]<=limd? values[node] : 0);
    int res2= 0;
    int juice=values[node];
    int day=days[node];

    for(auto thing:adj[node]){
        res+=dpf(thing, min(days[node], limd));
        res2+=dpf(thing, min((int)1e9, limd));
    }
    return max(res, res2);
}

void solve(){
    int n, m, k;cin>>n>>m>>k;
    values.assign(n+1, 0);
    days.assign(n+1, 0);
    adj.resize(n+1);
    for(int i = 2;i<=n;i++){
        int p;cin>>p;
        adj[p].push_back(i);
    }
    for(int i = 0;i<m;i++){
        int v, d, w;cin>>v>>d>>w;
        values[v]=w;
        days[v]=d;
    }
    cout << dpf(1, (int)1e9) << '\n';
    //with sets its total good time merging, but I also need to mantain 
    //like a double log n full I do have it but its so shitty i mean
    //39 minutes got all ideas exceot one
    //pretty sure 83 very doable because OOH WAIT
    //so returns a set<int>
    //when small to large merging then I can also detect needed day
    //all values of v distinct thus no vertex >1 fruit that's good
    //so for each subtree value, days not important UNLESS two on same day then if I want to cut
    //so cutting something annulates everything cut strictly after
    //so I will redo dfs, check values after
    //if values after contain bad bad bad >me juice, do nothing else cut. so
    //dpf(node) should return maximum juice value I can get after day x
    //so I should start at the root
    //then for each fruit I see (basically at every node)
    //I do:SMALL TO LARGE MERGING
    //like I will have times
    // times are very not good
    //so because those are sets I will swap em and redo
    //if done correctly with references then a good time
}











signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1;
    while (t--)
    {
        solve();
    }
    
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...