Submission #246280

# Submission time Handle Problem Language Result Execution time Memory
246280 2020-07-08T14:08:26 Z 2fat2code Magic Tree (CEOI19_magictree) C++17
3 / 100
156 ms 38500 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

const int nmax = 100005;

struct fruct{
    int prezent, day, juice;
    fruct(){prezent = -1;}
}a[nmax];

map<int,int>dp[nmax];
int n,m,k,dp_sub[nmax];
vector<int>nod[nmax];

void add(int indx, pair<int,int>val){
    dp[indx][val.fr] += val.sc;
}

void rationalize(int indx, pair<int,int>val){
    int precedent = dp[indx][val.fr];
    dp[indx][val.fr] += val.sc;
    auto it = dp[indx].upper_bound(val.fr);
    int curr = 0;
    while(it != dp[indx].end()){
        curr += (it->second - precedent);
        precedent = (it->second);
        if(curr > val.sc) break;
        else{
            auto tz = it;
            ++it;
            dp[indx].erase(tz);
        }
    }
    if(it != dp[indx].end()){
        dp[indx][it->first] = (curr - val.sc);
    }
}

void DFS(int s){
    int heavy = -1, sz = 0;
    for(auto it : nod[s]){
        DFS(it);
        dp_sub[s] += dp_sub[it];
        if(sz < dp_sub[it]){
            sz = dp_sub[it];
            heavy = it;
        }
    }
    dp_sub[s] ++;
    if(heavy != -1){
        swap(dp[s],dp[heavy]);
    }
    for(auto it : nod[s]){
        if(it != heavy){
            for(auto curr : dp[it]){
                add(s,curr);
            }
        }
    }
    if(a[s].prezent == 1){
        rationalize(s,{a[s].day, a[s].juice});
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n >> m >> k;
    for(int i=2;i<=n;i++){
        int x;
        cin >> x;
        nod[x].push_back(i);
    }
    for(int i=1;i<=m;i++){
        int x,y,z;
        cin >> x >> y >> z;
        a[x].prezent = 1;
        a[x].day = y;
        a[x].juice = z;
    }
    DFS(1);
    int ans = 0;
    for(auto it : dp[1]){
        ans += (it.sc);
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 21496 KB Output is correct
2 Correct 62 ms 22648 KB Output is correct
3 Correct 156 ms 38500 KB Output is correct
4 Correct 89 ms 22768 KB Output is correct
5 Correct 144 ms 24948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 18040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -