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
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M, K, res = 0;
cin >> N >> M >> K;
vector<int> g[N];
int d[N] {}, w[N] {};
for(int i = 1; i < N; i++) {
int p; cin >> p;
g[p-1].push_back(i);
}
while(M--) {
int u;
cin >> u >> d[u-1] >> w[u-1];
}
map<int, int> dp[N];
for(int u = N; --u >= 0; ) {
int h = 0;
for(int v : g[u])
if(size(dp[v]) > size(dp[h])) h = v;
dp[h].swap(dp[u]);
for(int v : g[u]) if(v != h)
for(auto &[i, j] : dp[v])
dp[u][i] += j;
dp[u][d[u]] += w[u];
auto f = dp[u].upper_bound(d[u]);
while(f != end(dp[u]) && ((*f).second -= w[u]) < 0)
w[u] = -(*f).second, f = dp[u].erase(f);
}
for(auto &[i, j] : dp[0]) res += j;
cout << res;
}
# | 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... |