제출 #31928

#제출 시각아이디문제언어결과실행 시간메모리
31928kazelBiochips (IZhO12_biochips)C++14
100 / 100
259 ms400728 KiB
#include<bits/stdc++.h> using namespace std; int val[200001], m, t; vector<int> g[200001]; int dp[200001][501], par[200001]; void dfs(int c) { par[c] = t; for(int e : g[c]) dfs(e); for(int i=1;i<=m;i++) dp[t+1][i] = max(dp[t][i],dp[par[c]][i-1]+val[c]); t++; } int main() { int n, r; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { int p; scanf("%d%d",&p,val+i); if(!p) r = i; else g[p].push_back(i); } for(int i=1;i<=m;i++) dp[0][i] = -1e9; dfs(r); printf("%d\n",dp[n][m]); }

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

biochips.cpp: In function 'int main()':
biochips.cpp:20:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
biochips.cpp:24:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&p,val+i);
                               ^
biochips.cpp:29:11: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dfs(r);
           ^
#Verdict Execution timeMemoryGrader output
Fetching results...