제출 #89839

#제출 시각아이디문제언어결과실행 시간메모리
89839Vardanyan바이오칩 (IZhO12_biochips)C++17
0 / 100
2057 ms404216 KiB
#pragma GCC optimize "-O3" #include<bits/stdc++.h> using namespace std; const int N = 200*1000+5; const int M = 505; int dp[N][M]; int tin[N]; int tout[N]; int a[N]; int d[N]; vector<int> g[N]; int timer = 0; void dfs(int v){ tin[v] = ++timer; d[timer] = a[v]; dp[timer][1] = a[v]; for(int i = 0;i<g[v].size();i++){ int to = g[v][i]; dfs(to); } tout[tin[v]] = timer; } int main() { int n,m; scanf("%d%d",&n,&m); int root; for(int i = 1;i<=n;i++){ int x,y; scanf("%d%d",&x,&y); if(x == 0) root = i; if(x){ g[x].push_back(i); } a[i] = y; } dfs(root); for(int j = 1;j<=m;j++){ for(int i = timer;i>=1;i--){ //cout<<d[i]<<endl; dp[i][j] = max(dp[i][j],dp[i+1][j]); if(tout[i]+1<=timer) dp[i][j] = max(dp[i][j],dp[tout[i]+1][j-1]+d[i]); } } cout<<dp[1][m]<<endl; return 0; }

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

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:17: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:26: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:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~
biochips.cpp:37:8: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dfs(root);
     ~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...