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 ll long long
const int nx=1e5+5, kx=21;
ll n, m, k, t[nx], w[nx], p, dp[nx][kx], x, ans, vl;
vector<int> d[nx];
void dfs(int u)
{
for (auto v:d[u])
{
dfs(v);
for (int i=1; i<=k; i++) dp[u][i]+=dp[v][i];
}
dp[u][t[u]]+=w[u];
for (int i=t[u]+1; i<=k; i++) dp[u][i]=max(dp[u][i], dp[u][i-1]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>k;
for (int i=2; i<=n; i++) cin>>p, d[p].push_back(i);
for (int i=1; i<=m; i++) cin>>x>>t[x]>>w[x];
dfs(1);
for (int i=1; i<=k; i++) ans=max(ans, dp[1][i]);
cout<<ans<<'\n';
}
# | 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... |