# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709372 | pauloamed | Magic Tree (CEOI19_magictree) | C++14 | 214 ms | 38256 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;
#define int long long
const int MAXN = 100010;
vector<int> v[MAXN];
int D[MAXN], W[MAXN];
map<int,int> f[MAXN];
void solve(int x) {
for(auto y : v[x]) {
solve(y);
if(f[y].size() > f[x].size()) swap(f[y], f[x]);
for(auto [t, w] : f[y]) f[x][t] += w;
}
if(D[x] == 0) return;
f[x][D[x]] += W[x];
int t = D[x];
int comp = W[x];
for(auto it = f[x].upper_bound(t); it != f[x].end(); it = f[x].upper_bound(t)) {
if(it->second <= comp) {
comp -= it->second;
f[x].erase(it);
} else {
it->second -= comp;
if(it->second == 0) f[x].erase(it);
break;
}
}
}
int32_t main(){
int n, m, k; cin >> n >> m >> k;
for(int i = 1; i < n; ++i) {
int p; cin >> p; p--;
v[p].push_back(i);
}
for(int i = 0; i < m; ++i) {
int x; cin >> x; x--;
cin >> D[x] >> W[x];
}
solve(0);
int ans = 0;
for(auto [a, b] : f[0]) ans += b;
cout << ans << "\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... |