# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89832 | 2018-12-18T14:12:12 Z | Vardanyan | 바이오칩 (IZhO12_biochips) | C++17 | 2000 ms | 370516 KB |
#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,int p = -1){ tin[v] = ++timer; d[timer] = a[v]; for(int i = 0;i<g[v].size();i++){ int to = g[v][i]; if(to == p) continue; dfs(to,v); } 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[i].push_back(x); g[x].push_back(i); } a[i] = y; } dfs(root); int ans = 0; for(int j = 1;j<=m;j++){ for(int i = timer;i>=1;i--){ //cout<<d[i]<<endl; if(j == 1){ dp[i][j] = d[i]; } 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]); if(j == m) ans = max(ans,dp[i][j]); } } cout<<ans<<endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4984 KB | Output is correct |
2 | Correct | 5 ms | 5236 KB | Output is correct |
3 | Correct | 1 ms | 5260 KB | Output is correct |
4 | Correct | 28 ms | 23096 KB | Output is correct |
5 | Correct | 32 ms | 25448 KB | Output is correct |
6 | Correct | 34 ms | 25464 KB | Output is correct |
7 | Correct | 1155 ms | 304720 KB | Output is correct |
8 | Correct | 1120 ms | 304776 KB | Output is correct |
9 | Execution timed out | 2084 ms | 370516 KB | Time limit exceeded |
10 | Halted | 0 ms | 0 KB | - |