# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981711 | duckindog | Magic Tree (CEOI19_magictree) | C++17 | 122 ms | 40632 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 N = 100'000 + 10;
int n, m, k;
vector<int> ad[N];
int d[N], w[N];
map<int, long long> f[N];
void merge(auto& x, auto& y) {
if (x.size() < y.size()) swap(x, y);
for (const auto& it : y) x[it.first] += it.second;
}
void dfs(int u, int p = 0) {
for (const auto& v : ad[u]) {
if (v == p) continue;
dfs(v, u);
merge(f[u], f[v]);
}
long long sum = w[u];
auto it = f[u].lower_bound(d[u] + 1);
while (it != f[u].end()) {
if (sum > it->second) {
sum -= it->second;
f[u].erase(it);
} else { it->second -= sum; break; }
it = f[u].lower_bound(d[u] + 1);
}
f[u][d[u]] += w[u];
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 2; i <= n; ++i) {
int v; cin >> v;
ad[i].push_back(v);
ad[v].push_back(i);
}
for (int i = 1; i <= m; ++i) {
int v; cin >> v >> d[v] >> w[v];
}
dfs(1);
long long answer = 0;
for (const auto& x : f[1]) answer += x.second;
cout << answer << "\n";
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |