답안 #89380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89380 2018-12-12T18:27:21 Z Vardanyan 바이오칩 (IZhO12_biochips) C++14
0 / 100
6 ms 4984 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200*1000+5;
vector<int> g[N];
int X[N];
int n,m;
int dp[N][505];
int knap[N][505];
int ans = 0;
void dfs(int v,int p = -1){
    dp[v][1] = X[v];
 //   if(m == 1) ans = max(ans,dp[v][1]);
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        dfs(to,v);
    }
    int cnt = 0;
  //  for(int i = 0;i<=g[v].size();i++)
    //    for(int j = 1;j<=m;j++) knap[i][j] = 0;
    for(int i = 0;i<g[v].size();i++){
        if(g[v][i] == p) continue;
        cnt++;
        for(int x = m;x>=0;x--){
            for(int y = x;y>=0;y--){
                for(int pos = 0;pos<cnt;pos++){
                    knap[cnt][x] = max(knap[cnt][x],knap[pos][x-y]+dp[g[v][i]][y]);
                    dp[v][x] = max(dp[v][x],knap[cnt][x]);
                    if(x == m) ans = max(ans,dp[v][x]);
                }
            }
        }
    }
}
int main(){
    scanf("%d%d",&n,&m);
    int root;
    for(int i = 1;i<=n;i++){
        int v,x;
        scanf("%d%d",&v,&x);
        X[i] = x;
        if(v == 0) {
            root = i;
            continue;
        }
        g[v].push_back(i);
        g[i].push_back(v);
    }
    dfs(root);
    printf("%d\n",ans);
	return 0;
}

Compilation message

biochips.cpp: In function 'void dfs(int, int)':
biochips.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
biochips.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
biochips.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v,&x);
         ~~~~~^~~~~~~~~~~~~~
biochips.cpp:49:8: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dfs(root);
     ~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -