제출 #928239

#제출 시각아이디문제언어결과실행 시간메모리
928239vjudge1Magic Tree (CEOI19_magictree)C++17
34 / 100
2029 ms95060 KiB
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define ll long long
#define maksim gay
#define int ll
#define pb push_back
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,i) memset(a,i,sizeof(a))
#define in insert
#define lb lower_bound
#define ub upper_bound

const int MAX=1e5+20;
const int inf=1e10;
const int N=2e5;

int n,m,k;
int dp[MAX][100];
int d[MAX],w[MAX];
vector<int> g[MAX];

void dfs(int v){
  for(auto to:g[v]){
    dfs(to);
    for(int j=0;j<=k;j++){
      dp[v][j]+=dp[to][j];
    }
  }
  dp[v][d[v]]+=w[v];
  for(int j=1;j<=k;j++){
    dp[v][j]=max(dp[v][j],dp[v][j-1]);
  }
  // cout<<"!! "<<v<<"\n";
  // for(int j=0;j<=k;j++){
  //   cout<<dp[v][j]<<" ";
  // }
  // cout<<"\n";
}

void solve(){
  cin>>n>>m>>k;
  for(int i=2;i<=n;i++){
    int p;
    cin>>p;
    g[p].pb(i);
  }
  for(int i=1;i<=m;i++){
    int v;
    cin>>v;
    cin>>d[v]>>w[v];
  }
  dfs(1);
  cout<<dp[1][k]<<"\n";
}


main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

컴파일 시 표준 에러 (stderr) 메시지

magictree.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...