답안 #956709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956709 2024-04-02T11:18:52 Z thangdz2k7 Magic Tree (CEOI19_magictree) C++17
58 / 100
111 ms 44116 KB
// author : HuuHung
// 25.3.2024


#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second
#define ll long long
#define lb long double
#define pb push_back
#define vi vector <int>
#define vll vector <ll>
#define Bit(x, i) ((x) >> (i) & 1)
#define Mask(i) (1ll << (i))
#define All(v) (v).begin(), (v).end()

using namespace std;

void maxzi(int &a, int b){
    a = max(a, b);
}

void minzi(int &a, int b){
    a = min(a, b);
}

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int LG = 20;

void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

int Pow(int a, int b){
    if (b == 0) return 1;
    if (b % 2) return 1ll * a * Pow(a, b - 1) % mod;
    int c = Pow(a, b / 2);
    return 1ll * c * c % mod;
}

// * end

int n, m, k;
int d[N], w[N];
vector <int> adj[N];
map <int, ll> dp[N];

void dfs(int u){
    for (int v : adj[u]){
        dfs(v);
        if (dp[u].size() < dp[v].size()) swap(dp[u], dp[v]);
        for (auto x : dp[v]) dp[u][x.F] += x.S;
    }

    if (d[u]){
        dp[u][d[u]] += w[u];
        for (auto x = dp[u].upper_bound(d[u]); x != dp[u].end();){
            if (x -> S > w[u]){
                x -> S -= w[u];
                break;
            }
            w[u] -= x -> S;
            dp[u].erase(x);
        }
    }
}

void solve(){
    cin >> n >> m >> k;
    for (int i = 2, p; i <= n; ++ i){
        cin >> p;
        adj[p].pb(i);
    }

    for (int i = 1, v; i <= m; ++ i){
        cin >> v;
        cin >> d[v] >> w[v];
    }

    dfs(1);
    ll ans = 0;
    for (auto v : dp[1]) ans += v.S;
    cout << ans;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t --) solve();

    return 0;
}





# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 25668 KB Output is correct
2 Correct 32 ms 26960 KB Output is correct
3 Correct 111 ms 44116 KB Output is correct
4 Correct 75 ms 27112 KB Output is correct
5 Correct 81 ms 29196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15448 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 15196 KB Output is correct
4 Correct 41 ms 34532 KB Output is correct
5 Correct 58 ms 38480 KB Output is correct
6 Correct 52 ms 34384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 34008 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14916 KB Output is correct
10 Correct 55 ms 25172 KB Output is correct
11 Correct 60 ms 23792 KB Output is correct
12 Correct 41 ms 25940 KB Output is correct
13 Correct 30 ms 22480 KB Output is correct
14 Correct 38 ms 33964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 30812 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14916 KB Output is correct
10 Correct 4 ms 15448 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 4 ms 15196 KB Output is correct
13 Correct 41 ms 34532 KB Output is correct
14 Correct 58 ms 38480 KB Output is correct
15 Correct 52 ms 34384 KB Output is correct
16 Correct 55 ms 25172 KB Output is correct
17 Correct 60 ms 23792 KB Output is correct
18 Correct 41 ms 25940 KB Output is correct
19 Correct 30 ms 22480 KB Output is correct
20 Correct 38 ms 33964 KB Output is correct
21 Correct 19 ms 18264 KB Output is correct
22 Correct 55 ms 25808 KB Output is correct
23 Correct 59 ms 29148 KB Output is correct
24 Correct 94 ms 37424 KB Output is correct
25 Correct 55 ms 26348 KB Output is correct
26 Correct 73 ms 28632 KB Output is correct
27 Correct 60 ms 28140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14916 KB Output is correct
10 Correct 54 ms 25668 KB Output is correct
11 Correct 32 ms 26960 KB Output is correct
12 Correct 111 ms 44116 KB Output is correct
13 Correct 75 ms 27112 KB Output is correct
14 Correct 81 ms 29196 KB Output is correct
15 Correct 4 ms 15448 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 4 ms 15196 KB Output is correct
18 Correct 41 ms 34532 KB Output is correct
19 Correct 58 ms 38480 KB Output is correct
20 Correct 52 ms 34384 KB Output is correct
21 Runtime error 42 ms 34008 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -