Submission #921735

# Submission time Handle Problem Language Result Execution time Memory
921735 2024-02-04T09:43:25 Z sleepntsheep Magic Tree (CEOI19_magictree) C++17
0 / 100
2000 ms 640204 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>

using u32 = unsigned;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

using namespace std;
using pt = complex<f80>;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 200005

multiset<pair<int, i64>> s[N];

int n, m, k; 
i64 dp[N];
basic_string<int> g[N];
deque<pair<int, i64>> pre[N];

void dfs(int u)
{
    i64 nocur = 0, cur = 0;
    for (auto v : g[u])
    {
        dfs(v);
        nocur += dp[v];
        if (s[v].size() > s[u].size()) s[v].swap(s[u]);
        for (auto &x : s[v]) s[u].insert(x);
    }

    {
        pre[u].emplace_back(k+1, 0);
        auto it = s[u].end();
        int day = -1, runningweight = 0;
        while (it != s[u].begin())
        {
            if (day != it->first)
            {
                pre[u].emplace_back(day, runningweight + pre[u].back().second);
                runningweight = it->second;
                day = it->first;
            }
            --it;
        }
        pre[u].emplace_back(day, runningweight + pre[u].back().second);
    }


    if (s[u].empty()) return void(dp[u] = nocur);

    auto [d, w] = *s[u].begin();
    cur = w;

    for (auto v : g[u])
    {
        dfs(v);
        int l = 0, r = (int)pre[v].size() - 1, z = -1;
        while (l <= r)
        {
            int m = (l+r)/2;
            if (pre[v][m].first <= d) l = m + 1, z = m;
            else r = m - 1;
        }
        if (z != -1) cur += pre[v][z].second;
    }

    dp[u] = max(cur, nocur);
}

int main()
{
    ShinLena;
    cin >> n >> m >> k;
    for (int i = 2, p; i <= n; ++i) cin >> p, g[p].push_back(i);
    for (int v, d, w, i = 0; i < m; ++i)
    {
        cin >> v >> d >> w;
        s[v].emplace(d, w);
    }
    dfs(1);
    cout << dp[1];

    return 0;
}


# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 152128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 510600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 497476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 562424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 152128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 640204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 152128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 152128 KB Output isn't correct
2 Halted 0 ms 0 KB -