답안 #435653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435653 2021-06-23T14:19:44 Z 2qbingxuan Worst Reporter 4 (JOI21_worst_reporter4) C++17
0 / 100
7 ms 7244 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (auto it = L; it != R; ++it)
        std::cerr << *it << ' ';
    std::cerr << "]\033[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)

using namespace std;
using ll = int64_t;
const int maxn = 100025, maxm = 10000;

int H[maxn], C[maxn];
vector<int> g[maxn];
map<int,ll> sub[maxn];
void insert(map<int,ll> &mp, int H, int v) {
    auto it = mp.lower_bound(H);
    if (it != mp.end() && it -> second >= v) return;
    while (it != mp.begin() && prev(it)->second >= v)
        mp.erase(prev(it));
    mp[H] = v;
}
ll query(map<int,ll> &mp, int H) {
    auto it = mp.lower_bound(H);
    if (it == mp.end()) return 0;
    return it -> second;
}
void join(int a, int b) {
    map<int,ll> result;
    for (auto [h, val]: sub[a])
        insert(result, h, val + query(sub[b], h));
    for (auto [h, val]: sub[b])
        insert(result, h, val + query(sub[a], h));
    sub[b] = result;
    sub[a].clear();
}
void dfs(int i) {
    ll value = C[i];
    for (int j: g[i]) {
        dfs(j);
        value += query(sub[j], H[i]);
        join(j, i);
    }
    insert(sub[i], H[i], value);
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    ll tot = 0;
    for (int i = 0; i < n; i++) {
        int A;
        cin >> A >> H[i] >> C[i];
        tot += C[i];
        --A;
        if (i) g[A].push_back(i);
    }
    dfs(0);
    ll best = 0;
    for (auto [h, val]: sub[0]) best = max(best, val);
    cout << tot - best << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -