Submission #841964

# Submission time Handle Problem Language Result Execution time Memory
841964 2023-09-02T09:24:46 Z browntoad Magic Tree (CEOI19_magictree) C++14
16 / 100
99 ms 19536 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i, n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define ppi pair<pii, int>
#define ppp pair<pii, pii>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif

const ll inf = 1ll<<60;
const ll iinf = 2147483647;
const ll mod = 998244353;
const ll maxn=1e5+5;
const double PI=acos(-1);

ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}

ll inv(ll a, ll m=mod){
    return pw(a,m-2,m);
}
int n, m, k;
set<pii> dp[maxn];
vector<int> graph[maxn];
vector<pii> froot(maxn); // first is time, second is weight
void dfs(int x){
    pii lg = {0, -1};
    REP(i, SZ(graph[x])){
        dfs(graph[x][i]);
        if (SZ(dp[graph[x][i]]) > lg.f) {
            lg.f = SZ(dp[graph[x][i]]);
            lg.s = i;
        }
    }
    if (lg.s != -1) dp[x].swap(dp[graph[x][lg.s]]);
    REP(i, SZ(graph[x])){
        if (i == lg.s) continue;
        while(dp[graph[x][i]].size()){
            dp[x].insert(*(dp[graph[x][i]].begin()));
            dp[graph[x][i]].erase(dp[graph[x][i]].begin());
        }
    }
    if (froot[x].f == 0) return;
    if (SZ(dp[x])){
        auto it = dp[x].upper_bound({froot[x].f+1, 0});
        int cur = -(froot[x].s);
        while(it != dp[x].end()){
            cur += (*it).s;
            if (cur > 0){
                dp[x].insert({(*it).f, cur});
                dp[x].erase(it);
                break;
            }
            it = dp[x].erase(it);
        }
    }
    dp[x].insert(froot[x]);
}
signed main(){
    IOS();
    cin>>n>>m>>k;
    FOR(i, 2, n+1){
        int p; cin>>p;
        graph[p].pb(i);
    }
    REP(i, m){
        int x; cin>>x;
        cin>>froot[x].f>>froot[x].s;
    }
    dfs(1);
    int ans = 0;
    while(dp[1].size()){
        ans += (*(dp[1].begin())).s;
        dp[1].erase(dp[1].begin());
    }
    cout<<ans<<endl;
}

# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13396 KB Output is correct
2 Correct 30 ms 18712 KB Output is correct
3 Correct 99 ms 18372 KB Output is correct
4 Correct 51 ms 17360 KB Output is correct
5 Correct 70 ms 19536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 17480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9564 KB Output is correct
2 Correct 19 ms 11356 KB Output is correct
3 Correct 27 ms 11528 KB Output is correct
4 Correct 18 ms 11356 KB Output is correct
5 Correct 7 ms 10460 KB Output is correct
6 Correct 18 ms 13912 KB Output is correct
7 Correct 18 ms 17232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -