This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 22.08.2023 09:39:57
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> g(n);
for (int i = 1; i < n; i++) {
int p;
cin >> p;
--p;
g[p].push_back(i);
}
vector<int> x(n, -1), y(n);
for (int i = 0; i < m; i++) {
int v, d, w;
cin >> v >> d >> w;
--v; --d;
x[v] = d;
y[v] = w;
}
vector<vector<long long>> dp(n, vector<long long>(k));
/* vector<int> f(n);
auto Insert = [&](int v, int d, int val) {
long long s = 0;
for (auto& p : dp[f[v]]) {
if (p.first < d) {
s += p.first;
if (s > val) {
break;
}
} else {
break;
}
}
if (s <= val) {
while (!dp[f[v]].empty() && dp[f[v]].begin()->first < d) {
dp[f[v]].erase(dp[f[v]].begin());
}
dp[f[v]].emplace(d, val);
}
}; */
function<void(int)> Solve = [&](int v) {
for (int u : g[v]) {
Solve(u);
}
for (int u : g[v]) {
for (int i = 0; i < k; i++) {
long long mx = 0;
for (int j = 0; j <= i; j++) {
mx = max(mx, dp[u][j]);
}
dp[v][i] += mx;
}
}
if (x[v] != -1) {
dp[v][x[v]] += y[v];
}
};
Solve(0);
cout << *max_element(dp[0].begin(), dp[0].end()) << '\n';
return 0;
}
# | 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... |