Submission #723537

# Submission time Handle Problem Language Result Execution time Memory
723537 2023-04-14T04:35:00 Z dxz05 Magic Tree (CEOI19_magictree) C++17
0 / 100
2000 ms 8624 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;

vector<int> g[N];
int tin[N], tout[N], timer = 0;
void dfs(int v){
    tin[v] = tout[v] = ++timer;
    for (int u : g[v]){
        dfs(u);
        tout[v] = tout[u];
    }
}

bool is_ancestor(int p, int v){
    return tin[p] <= tin[v] && tout[v] <= tout[p];
}

void solve(){
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 2; i <= n; i++){
        int p;
        cin >> p;
        g[p].push_back(i);
    }

    dfs(1);

    vector<tuple<int, int, int>> fruits;
    for (int i = 0; i < m; i++){
        int v, d, w;
        cin >> v >> d >> w;
        fruits.emplace_back(v, d, w);
    }

    ll ans = 0;
    for (int i = 0; i < m; i++){
        ll sum = 0;
        int v = get<0>(fruits[i]);

        for (int j = 0; j < m; j++){
            if (i == j) continue;

            auto [u, d, w] = fruits[j];

            if (is_ancestor(v, u) && d > get<1>(fruits[i])) sum += w;
        }
        if (sum <= get<2>(fruits[i])){
            ans += get<2>(fruits[i]);
        }
    }

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2036 ms 6416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2058 ms 8624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 3284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -