답안 #89377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89377 2018-12-12T18:09:16 Z Vardanyan 바이오칩 (IZhO12_biochips) C++14
0 / 100
987 ms 400504 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];
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        dfs(to,v);
    }
    int cnt = 0;
    memset(knap,0,sizeof(knap));
    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[g[v][i]][x] = max(dp[g[v][i]][x],knap[cnt][x]);
                    if(x == m) ans = max(ans,dp[g[v][i]][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:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
biochips.cpp:19: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:34: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:38: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:47:8: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dfs(root);
     ~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 987 ms 400504 KB Output isn't correct
2 Halted 0 ms 0 KB -