# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
31928 | 2017-09-16T08:42:40 Z | kazel | 바이오칩 (IZhO12_biochips) | C++14 | 259 ms | 400728 KB |
#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]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 399672 KB | Output is correct |
2 | Correct | 0 ms | 399672 KB | Output is correct |
3 | Correct | 3 ms | 399672 KB | Output is correct |
4 | Correct | 9 ms | 399804 KB | Output is correct |
5 | Correct | 13 ms | 399804 KB | Output is correct |
6 | Correct | 6 ms | 399804 KB | Output is correct |
7 | Correct | 163 ms | 400728 KB | Output is correct |
8 | Correct | 156 ms | 400728 KB | Output is correct |
9 | Correct | 159 ms | 400728 KB | Output is correct |
10 | Correct | 259 ms | 400728 KB | Output is correct |