답안 #259906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259906 2020-08-08T19:23:58 Z MarcoMeijer Magic Tree (CEOI19_magictree) C++14
100 / 100
204 ms 51064 KB
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()

// input
template<class T> void IN(T& x) {cin >> x;}
template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); }

// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi," ",x.se);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    program();
}


//===================//
//   begin program   //
//===================//

const int MX = 2e5;
int n, m, k;
int p[MX];
int v[MX], d[MX], w[MX];
int D[MX], W[MX];
vi chl[MX];
map<ll,ll> dp[MX];

void add(map<ll,ll>& mp, ll d, ll w) {
    mp[d] += w;

    auto it = mp.upper_bound(d);
    while(w && it!=mp.end()) {
        if(w >= it->se) {
            w -= it->se;
            it = mp.erase(it);
        } else {
            it->se -= w;
            w = 0;
        }
    }
}
void combine(map<ll,ll>& a, map<ll,ll>& b) {
    if(a.sz < b.sz) swap(a,b);
    FOR(p,b) a[p.fi] += p.se;
}

void program() {
    IN(n,m,k);
    REI(i,2,n) IN(p[i]);
    RE(i,m) IN(v[i],d[i],w[i]);
    RE1(i,n) D[i]=k+1, W[i]=0;
    RE(i,m) D[v[i]]=d[i], W[v[i]]=w[i];

    REI(i,2,n) chl[p[i]].pb(i);

    REV(i,2,n+1) {
        if(W[i]) add(dp[i], D[i], W[i]);
        combine(dp[p[i]], dp[i]);
    }

    ll ans=0;
    FOR(p,dp[1]) ans+=p.se;
    OUTL(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 9 ms 14464 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 26956 KB Output is correct
2 Correct 52 ms 21496 KB Output is correct
3 Correct 204 ms 51064 KB Output is correct
4 Correct 113 ms 28612 KB Output is correct
5 Correct 152 ms 34296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 70 ms 19960 KB Output is correct
5 Correct 95 ms 23928 KB Output is correct
6 Correct 92 ms 20116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 22136 KB Output is correct
2 Correct 77 ms 21240 KB Output is correct
3 Correct 70 ms 20344 KB Output is correct
4 Correct 63 ms 22772 KB Output is correct
5 Correct 63 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 9 ms 14464 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 99 ms 25720 KB Output is correct
11 Correct 95 ms 24696 KB Output is correct
12 Correct 65 ms 20472 KB Output is correct
13 Correct 55 ms 22644 KB Output is correct
14 Correct 59 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 15232 KB Output is correct
2 Correct 36 ms 17400 KB Output is correct
3 Correct 36 ms 17400 KB Output is correct
4 Correct 35 ms 17528 KB Output is correct
5 Correct 20 ms 16256 KB Output is correct
6 Correct 33 ms 17024 KB Output is correct
7 Correct 33 ms 18168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 9 ms 14464 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 10 ms 14464 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 10 ms 14464 KB Output is correct
13 Correct 70 ms 19960 KB Output is correct
14 Correct 95 ms 23928 KB Output is correct
15 Correct 92 ms 20116 KB Output is correct
16 Correct 99 ms 25720 KB Output is correct
17 Correct 95 ms 24696 KB Output is correct
18 Correct 65 ms 20472 KB Output is correct
19 Correct 55 ms 22644 KB Output is correct
20 Correct 59 ms 19832 KB Output is correct
21 Correct 33 ms 18680 KB Output is correct
22 Correct 91 ms 28536 KB Output is correct
23 Correct 108 ms 32120 KB Output is correct
24 Correct 170 ms 43256 KB Output is correct
25 Correct 126 ms 27892 KB Output is correct
26 Correct 159 ms 29176 KB Output is correct
27 Correct 99 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 9 ms 14464 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 78 ms 26956 KB Output is correct
11 Correct 52 ms 21496 KB Output is correct
12 Correct 204 ms 51064 KB Output is correct
13 Correct 113 ms 28612 KB Output is correct
14 Correct 152 ms 34296 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 10 ms 14464 KB Output is correct
18 Correct 70 ms 19960 KB Output is correct
19 Correct 95 ms 23928 KB Output is correct
20 Correct 92 ms 20116 KB Output is correct
21 Correct 80 ms 22136 KB Output is correct
22 Correct 77 ms 21240 KB Output is correct
23 Correct 70 ms 20344 KB Output is correct
24 Correct 63 ms 22772 KB Output is correct
25 Correct 63 ms 19832 KB Output is correct
26 Correct 99 ms 25720 KB Output is correct
27 Correct 95 ms 24696 KB Output is correct
28 Correct 65 ms 20472 KB Output is correct
29 Correct 55 ms 22644 KB Output is correct
30 Correct 59 ms 19832 KB Output is correct
31 Correct 15 ms 15232 KB Output is correct
32 Correct 36 ms 17400 KB Output is correct
33 Correct 36 ms 17400 KB Output is correct
34 Correct 35 ms 17528 KB Output is correct
35 Correct 20 ms 16256 KB Output is correct
36 Correct 33 ms 17024 KB Output is correct
37 Correct 33 ms 18168 KB Output is correct
38 Correct 33 ms 18680 KB Output is correct
39 Correct 91 ms 28536 KB Output is correct
40 Correct 108 ms 32120 KB Output is correct
41 Correct 170 ms 43256 KB Output is correct
42 Correct 126 ms 27892 KB Output is correct
43 Correct 159 ms 29176 KB Output is correct
44 Correct 99 ms 23928 KB Output is correct
45 Correct 36 ms 19328 KB Output is correct
46 Correct 100 ms 29688 KB Output is correct
47 Correct 110 ms 33872 KB Output is correct
48 Correct 184 ms 46588 KB Output is correct
49 Correct 133 ms 28540 KB Output is correct
50 Correct 154 ms 30072 KB Output is correct
51 Correct 104 ms 24900 KB Output is correct