Submission #972782

# Submission time Handle Problem Language Result Execution time Memory
972782 2024-05-01T07:14:08 Z phoenix Magic Tree (CEOI19_magictree) C++17
0 / 100
776 ms 28820 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 Incorrect 2 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 776 ms 28820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 745 ms 20404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 9632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -