Submission #1236028

#TimeUsernameProblemLanguageResultExecution timeMemory
1236028dssfsuper2Magic Tree (CEOI19_magictree)C++20
0 / 100
355 ms795052 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int, int>;
#define all(x) (x).begin(), (x).end()


vector<int> values;
vector<int> days;
vector<vector<int>> adj;
map<int, int> dayscompressed;

int dp[100001][1005];
int maxx[100001];
int tt;
int dpf(int node, int limd){
    int res2= 0;
    for(auto thing:adj[node]){
        res2+=dpf(thing, min((int)1e9, limd));
    }
    if(maxx[node]<=days[node] && values[node]==1)res2++; 
    dp[node][limd]=res2+1;
    //if there are no days over days[node] in subtree and my value is 1, then res++
    return res2;
}

int maxds(int node){
    int res = days[node];
    for(auto thing:adj[node]){
        res=max(res, maxds(thing));
    }
    maxx[node]=res;
    return res;
}
void solve(){
    int n, m, k;cin>>n>>m>>k;
    values.assign(n+1, 0);
    days.assign(n+1, 0);
    adj.resize(n+1);
    fill(*dp, *dp+100001*1005, 0);
    vector<int> ds = {0};
    
    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;
        ds.push_back(d);
    }
    sort(all(ds));
    int cp=0;
    for(int i = 0;i<ds.size();i++){
        if(i==0 || ds[i]!=ds[i-1]){
            dayscompressed[ds[i]]=cp;
            cp++;
        }
    }
    tt=cp;
    dayscompressed[(int)1e9]=cp;
    for(auto& thing:days){
        thing=dayscompressed[thing];
    }
    bool isss3 = (*max_element(all(values))==1);
    maxds(1);
    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...