Submission #598594

# Submission time Handle Problem Language Result Execution time Memory
598594 2022-07-18T14:40:23 Z Valaki2 Magic Tree (CEOI19_magictree) C++14
3 / 100
71 ms 14432 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back

const int maxn = 1e5;

struct fruit {
    int vertex, day, weight;
    fruit() : vertex(0), day(0), weight(0) {}
    fruit(int vertex_, int day_, int weight_) :
        vertex(vertex_), day(day_), weight(weight_) {}
};

int n, m, k;
int par[maxn + 1];
vector<int> children[maxn + 1];
bool has_fruit[maxn + 1];
fruit fruit_of[maxn + 1];
vector<fruit> fruits;
int dp[maxn + 1];
set<int> days;

vector<int> init_dfs(int cur) {
    vector<int> v;
    for(int nei : children[cur]) {
        vector<int> v2 = init_dfs(nei);
        for(int x : v2) {
            v.pb(x);
        }
    }
    if(has_fruit[cur] || cur == 1) {
        children[cur] = v;
        return vector<int> (1, cur);
    }
    return v;
}

void dfs(int cur, int &d) {
    int sum = 0;
    for(int nei : children[cur]) {
        dfs(nei, d);
        sum += dp[nei];
    }
    if(has_fruit[cur] && fruit_of[cur].day == d) {
        sum += fruit_of[cur].weight;
    }
    dp[cur] = max(dp[cur], sum);
}

void solve() {
    cin >> n >> m >> k;
    for(int i = 2; i <= n; i++) {
        cin >> par[i];
        children[par[i]].pb(i);
    }
    fruits.assign(m, fruit());
    int ans = 0;
    for(int i = 0; i < m; i++) {
        cin >> fruits[i].vertex >> fruits[i].day >> fruits[i].weight;
        has_fruit[fruits[i].vertex] = true;
        days.insert(fruits[i].day);
        fruit_of[fruits[i].vertex] = fruits[i];
        ans += fruits[i].weight;
    }
    cout << ans << "\n";
    return;
    init_dfs(1);
    for(int d : days) {
        dfs(1, d);
    }
    cout << dp[1] << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 9276 KB Output is correct
2 Correct 25 ms 9648 KB Output is correct
3 Correct 58 ms 14432 KB Output is correct
4 Correct 53 ms 13572 KB Output is correct
5 Correct 71 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -