Submission #972783

# Submission time Handle Problem Language Result Execution time Memory
972783 2024-05-01T07:14:21 Z phoenix Magic Tree (CEOI19_magictree) C++17
16 / 100
100 ms 36280 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 100100;

int n, m, k;

int p[N];
int d[N];
int w[N];

map<int, ll> mp[N];
vector<int> g[N];

int unite(int i, int j) {
    if ((int)mp[i].size() < (int)mp[j].size()) swap(i, j);
    for (auto c : mp[j]) 
        mp[i][c.first] += c.second;
    return i;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 2; i <= n; i++) {
        cin >> p[i];
        g[p[i]].push_back(i);
    }
    for (int i = 0; i < m; i++) {
        int v;
        cin >> v;
        cin >> d[v] >> w[v];    

    }

    for (int v = n; v >= 1; v--) {
        int heavy = 0;      
        for (int c : g[v]) 
            if ((int)mp[c].size() > (int)mp[heavy].size())
                heavy = c;
        swap(mp[heavy], mp[v]);
        for (int c : g[v]) 
            unite(v, c);
        auto it = mp[v].lower_bound(d[v]);
        int s = w[v];
        while (it != mp[v].end()) {
            if (it->second <= s) {
                s -= it->second;
                mp[v].erase(it);
            } else {
                mp[v][it->first] = it->second - s;
                break;
            }
            it = mp[v].lower_bound(d[v]);
        }
        mp[v][d[v]] += w[v];
        // cerr << "vertex: " << v << "\n";
        // cerr << "{";
        // for (auto c : mp[v]) cout << '(' << c.first << ' ' << c.second << ')' << ' ';
        // cerr << "}\n";
    }
    ll s = 0;
    for (auto c : mp[1])
        s += c.second;
    cout << s << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Incorrect 5 ms 7348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 20444 KB Output is correct
2 Correct 30 ms 14428 KB Output is correct
3 Correct 100 ms 36280 KB Output is correct
4 Correct 63 ms 21196 KB Output is correct
5 Correct 73 ms 21076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 14504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Incorrect 5 ms 7348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8796 KB Output is correct
2 Correct 23 ms 13928 KB Output is correct
3 Correct 35 ms 13908 KB Output is correct
4 Correct 24 ms 14168 KB Output is correct
5 Correct 16 ms 15580 KB Output is correct
6 Correct 22 ms 14424 KB Output is correct
7 Correct 21 ms 12964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Incorrect 5 ms 7348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Incorrect 5 ms 7348 KB Output isn't correct
3 Halted 0 ms 0 KB -