# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392299 | MiricaMatei | Worst Reporter 4 (JOI21_worst_reporter4) | C++14 | 11 ms | 10316 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int inf = 2000000000;
struct slope_trick {
map<int, long long> delta;
void mergeDelta(slope_trick other) {
for (auto it:other.delta)
delta[it.first] += it.second;
other.delta.clear();
}
void add(int x, int val) {
delta[-inf] += val;
delta[x] -= val;
delta[x + 1] += val;
map<int, long long>::iterator it1, it2;
it1 = delta.lower_bound(x);
val = delta[x];
while (val <= 0) {
it2 = it1;
it1--;
delta.erase(it2);
val = it1->second + val;
it1->second = val;
}
}
int mapSize() {
return delta.size();
}
long long query() {
return delta[-inf];
}
};
vector<int>G[MAXN];
int a[MAXN], h[MAXN], c[MAXN];
slope_trick dfs(int node) {
slope_trick ans;
for (auto it:G[node]) {
slope_trick aux = dfs(it);
if (aux.mapSize() > ans.mapSize())
swap(ans, aux);
ans.mergeDelta(aux);
}
ans.add(h[node], c[node]);
return ans;
}
long long solve(int node) {
slope_trick ans = dfs(node);
return ans.query();
}
int main() {
//freopen("date.in", "r", stdin);
//freopen("date.out", "w", stdout);
int N;
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%d%d%d", &a[i], &h[i], &c[i]);
if (i > 1)
G[a[i]].push_back(i);
}
long long ans = solve(1);
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |