# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095755 | alexander707070 | Magic Tree (CEOI19_magictree) | C++14 | 85 ms | 40764 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>
#define MAXN 100007
using namespace std;
int n,m,k,p[MAXN],a,d,w;
pair<int,int> cost[MAXN];
vector<int> v[MAXN];
long long dp[MAXN][27];
bool vis[MAXN][27];
long long ff(int x,int day){
if(vis[x][day])return dp[x][day];
vis[x][day]=true;
if(day==cost[x].first)dp[x][day]+=cost[x].second;
for(int i=0;i<v[x].size();i++){
dp[x][day]+=ff(v[x][i],day);
}
if(day>1)dp[x][day]=max(dp[x][day],ff(x,day-1));
return dp[x][day];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=2;i<=n;i++){
cin>>p[i];
v[p[i]].push_back(i);
}
for(int i=1;i<=m;i++){
cin>>a>>d>>w;
cost[a]={d,w};
}
cout<<ff(1,20)<<"\n";
return 0;
}
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... |