Submission #547669

# Submission time Handle Problem Language Result Execution time Memory
547669 2022-04-11T10:04:40 Z gimabd30 Magic Tree (CEOI19_magictree) C++17
100 / 100
171 ms 39884 KB
//#define _GLIBCXX_DEBUG

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
using normal_queue = priority_queue <T, vector<T>, greater<>>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define trace(x) cout << #x << ": " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define ld long double
#define sz(s) ((int) size(s))
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define int128 __int128
#define pb push_back
#define eb emplace_back


template<typename T>
bool ckmn(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool ckmx(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

int bit(int x, int b) {
    return (x >> b) & 1;
}


int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

//soryan za musor sverhu

const ll infL = 3e18;
const int infI = 1e9 + 7;
const int N = 100001;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;

int t[N], w[N], p[N];

map<int, ll> mp[N]; //dp[v][t] - answer if the max time when we cut in subtree of v is <= t


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        --p[i];
    }
    for (int i = 0; i < m; ++i) {
        int v, d, ww;
        cin >> v >> d >> ww;
        --v;
        t[v] = d, w[v] = ww;
    }
    for (int i = n - 1; i > 0; --i) {
        if (w[i] != 0) {
            mp[i][t[i]] += w[i];
            while (true) {
                auto it = mp[i].upper_bound(t[i]);
                if (it == end(mp[i])) break;
                if (it->second > w[i]) {
                    it->second -= w[i];
                    break;
                } else {
                    w[i] -= it->second;
                    mp[i].erase(it);
                }
            }
        }
        if (sz(mp[p[i]]) < sz(mp[i])) swap(mp[p[i]], mp[i]);
        for (auto [aa, bb] : mp[i]) mp[p[i]][aa] += bb;
    }
    ll ans = 0;
    for (auto [aa, bb] : mp[0]) ans += bb;
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 16808 KB Output is correct
2 Correct 29 ms 9680 KB Output is correct
3 Correct 171 ms 39884 KB Output is correct
4 Correct 83 ms 17568 KB Output is correct
5 Correct 101 ms 22840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 36 ms 8100 KB Output is correct
5 Correct 58 ms 11972 KB Output is correct
6 Correct 50 ms 8024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 12088 KB Output is correct
2 Correct 38 ms 11164 KB Output is correct
3 Correct 42 ms 9420 KB Output is correct
4 Correct 46 ms 13464 KB Output is correct
5 Correct 33 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 58 ms 15104 KB Output is correct
11 Correct 53 ms 13844 KB Output is correct
12 Correct 35 ms 8860 KB Output is correct
13 Correct 42 ms 12812 KB Output is correct
14 Correct 34 ms 7628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5552 KB Output is correct
2 Correct 11 ms 6868 KB Output is correct
3 Correct 12 ms 6964 KB Output is correct
4 Correct 12 ms 6996 KB Output is correct
5 Correct 8 ms 6484 KB Output is correct
6 Correct 13 ms 6752 KB Output is correct
7 Correct 13 ms 6732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 36 ms 8100 KB Output is correct
14 Correct 58 ms 11972 KB Output is correct
15 Correct 50 ms 8024 KB Output is correct
16 Correct 58 ms 15104 KB Output is correct
17 Correct 53 ms 13844 KB Output is correct
18 Correct 35 ms 8860 KB Output is correct
19 Correct 42 ms 12812 KB Output is correct
20 Correct 34 ms 7628 KB Output is correct
21 Correct 19 ms 8660 KB Output is correct
22 Correct 51 ms 16852 KB Output is correct
23 Correct 75 ms 20416 KB Output is correct
24 Correct 115 ms 31128 KB Output is correct
25 Correct 78 ms 16932 KB Output is correct
26 Correct 87 ms 17296 KB Output is correct
27 Correct 65 ms 10772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 51 ms 16808 KB Output is correct
11 Correct 29 ms 9680 KB Output is correct
12 Correct 171 ms 39884 KB Output is correct
13 Correct 83 ms 17568 KB Output is correct
14 Correct 101 ms 22840 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 36 ms 8100 KB Output is correct
19 Correct 58 ms 11972 KB Output is correct
20 Correct 50 ms 8024 KB Output is correct
21 Correct 42 ms 12088 KB Output is correct
22 Correct 38 ms 11164 KB Output is correct
23 Correct 42 ms 9420 KB Output is correct
24 Correct 46 ms 13464 KB Output is correct
25 Correct 33 ms 8268 KB Output is correct
26 Correct 58 ms 15104 KB Output is correct
27 Correct 53 ms 13844 KB Output is correct
28 Correct 35 ms 8860 KB Output is correct
29 Correct 42 ms 12812 KB Output is correct
30 Correct 34 ms 7628 KB Output is correct
31 Correct 6 ms 5552 KB Output is correct
32 Correct 11 ms 6868 KB Output is correct
33 Correct 12 ms 6964 KB Output is correct
34 Correct 12 ms 6996 KB Output is correct
35 Correct 8 ms 6484 KB Output is correct
36 Correct 13 ms 6752 KB Output is correct
37 Correct 13 ms 6732 KB Output is correct
38 Correct 19 ms 8660 KB Output is correct
39 Correct 51 ms 16852 KB Output is correct
40 Correct 75 ms 20416 KB Output is correct
41 Correct 115 ms 31128 KB Output is correct
42 Correct 78 ms 16932 KB Output is correct
43 Correct 87 ms 17296 KB Output is correct
44 Correct 65 ms 10772 KB Output is correct
45 Correct 20 ms 9296 KB Output is correct
46 Correct 61 ms 18064 KB Output is correct
47 Correct 89 ms 22204 KB Output is correct
48 Correct 132 ms 34476 KB Output is correct
49 Correct 76 ms 17612 KB Output is correct
50 Correct 100 ms 18164 KB Output is correct
51 Correct 69 ms 11708 KB Output is correct