제출 #483906

#제출 시각아이디문제언어결과실행 시간메모리
483906FatihSolak바이오칩 (IZhO12_biochips)C++17
0 / 100
161 ms13040 KiB
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int n,m;
vector<int> adj[N];
int par[N];
int arr[N];
int ans = 0;
vector<int> dfs(int v,int c,vector<int> dp){
    dp[0] = 0;
    vector<int> tmp = dp;
    for(auto u:adj[v]){
        if(u == c)continue;
        dp = dfs(u,-1,dp);
    }
    for(int i=1;i<=m;i++){
        dp[i] = max(dp[i],tmp[i-1]+arr[v]);
    }
    ans = max(ans,dp[m]);
    if(c != -1 && par[v]){
        dfs(par[v],v,dp);
    }
    /*
    cout << v << endl;
    for(auto u:dp){
        cout << u << " ";
    }
    cout << endl;*/
    return dp;
}
void solve(){
    cin >> n >> m;
    int root = 0;
    for(int i=1;i<=n;i++){
        cin >> par[i] >> arr[i];
        if(par[i] == 0)root = i;
        else adj[par[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){
        if(adj[i].empty()){
            dfs(i,0,vector<int>(m+1,-1e9));
            break;
        }
    }
    cout << ans << endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

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

biochips.cpp: In function 'void solve()':
biochips.cpp:33:9: warning: variable 'root' set but not used [-Wunused-but-set-variable]
   33 |     int root = 0;
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...