Submission #598612

# Submission time Handle Problem Language Result Execution time Memory
598612 2022-07-18T15:11:06 Z Valaki2 Magic Tree (CEOI19_magictree) C++14
11 / 100
61 ms 26616 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 d_ptr[maxn + 1];
vector<int> d[maxn + 1];

void dfs(int cur) {
    for(int nei : children[cur]) {
        dfs(nei);
    }
    d_ptr[cur] = cur;
    int which = 0;
    for(int nei : children[cur]) {
        if(d[d_ptr[nei]].size() > d[d_ptr[cur]].size()) {
            d_ptr[cur] = d_ptr[nei];
            which = nei;
        }
    }
    for(int nei : children[cur]) {
        if(which != nei) {
            vector<int> v = d[d_ptr[nei]];
            int v_size = v.size();
            for(int i = 0; i < v_size; i++) {
                if(d[d_ptr[cur]][i] > v[i]) {
                    d[d_ptr[cur]][i] = v[i];
                }
            }
        }
    }
    if(has_fruit[cur]) {
        auto it = upper_bound(d[d_ptr[cur]].begin(), d[d_ptr[cur]].end(), fruit_of[cur].day);
        if(it == d[d_ptr[cur]].end()) {
            d[d_ptr[cur]].pb(fruit_of[cur].day);
        } else {
            *it = fruit_of[cur].day;
        }
    }
}

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());
    for(int i = 0; i < m; i++) {
        cin >> fruits[i].vertex >> fruits[i].day >> fruits[i].weight;
        has_fruit[fruits[i].vertex] = true;
        fruit_of[fruits[i].vertex] = fruits[i];
    }
    dfs(1);
    cout << (int) (d[d_ptr[1]].size()) << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 12096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 43 ms 23792 KB Output is correct
5 Correct 44 ms 26616 KB Output is correct
6 Correct 50 ms 25828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 14540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -