답안 #833744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833744 2023-08-22T08:26:10 Z FEDIKUS Magic Tree (CEOI19_magictree) C++17
15 / 100
181 ms 35268 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

const ll maxn=1e5+10;

ll p[maxn];
vector<ll> g[maxn];
pair<ll,ll> f[maxn];

set<pair<ll,ll> > dp[maxn]; // obrisao sam ceo subtree pre first-og dana i zaradio second vise nego za prosli koji imam sacuvan

void dodajsub(pair<ll,ll> f,set<pii> &dp){
    auto it=dp.lower_bound({f.first,-1});
    if(it==dp.end()){
        dp.emplace(f);
        return;
    }
    if(it->first!=f.first){
        dp.emplace(f);
        return;
    }
    pii nov=*it;
    nov.second+=f.second;
    dp.erase(it);
    dp.emplace(nov);
}

void dodajcale(pii f,set<pii> &dp){
    auto it=dp.lower_bound({f.first,-1});
    if(it==dp.end()){
        dp.emplace(f);
        return;
    }
    pii nov=f;
    if(it->first==f.first){
        nov.second+=it->second;
        dp.erase(it);
    }
    it=dp.lower_bound({f.first,-1});
    while(it!=dp.end() && it->second<=f.second){
        dp.erase(it);
        it=dp.lower_bound({f.first,-1});
    }
    if(it==dp.end()){
        dp.emplace(nov);
        return;
    }
    pii sled=*it;
    dp.erase(it);
    dp.emplace(nov);
    sled.second-=f.second;
    dp.emplace(sled);
}

void dfs(ll node=1){
    for(ll i:g[node]) dfs(i);
    pair<ll,ll> maxi={-1,-1};
    for(ll i:g[node]) maxi=max(maxi,pii(dp[i].size(),i));
    if(maxi.second!=-1){
        swap(dp[node],dp[maxi.second]);
        for(ll i:g[node]){
            if(i==maxi.second) continue;
            for(auto j:dp[i]){
                dodajsub(j,dp[node]);
            }
        }
    }
    if(f[node].first!=-1) dodajcale(f[node],dp[node]);

    /*cout<<node<<":\n";
    for(auto i:dp[node]) cout<<i.first<<" "<<i.second<<"\n";
    cout<<"\n";*/
}

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    for(ll i=2;i<=n;i++){
        cin>>p[i];
        g[p[i]].push_back(i);
    }
    for(ll i=1;i<=n;i++) f[i]={-1,-1};
    for(ll i=0;i<m;i++){
        ll v,d,w; cin>>v>>d>>w;
        f[v]={d,w};
    }
    dfs();
    ll res=0;
    for(auto i:dp[1]) res+=i.second;
    cout<<res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 19084 KB Output is correct
2 Correct 56 ms 18304 KB Output is correct
3 Correct 181 ms 35268 KB Output is correct
4 Correct 113 ms 19772 KB Output is correct
5 Correct 176 ms 21068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 15180 KB Output is correct
2 Correct 100 ms 16460 KB Output is correct
3 Correct 98 ms 18508 KB Output is correct
4 Correct 78 ms 17748 KB Output is correct
5 Correct 101 ms 22732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -