# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
81139 | wzy | 바이오칩 (IZhO12_biochips) | C++11 | 6 ms | 5084 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define time tr
#define pb push_back
int c[200005], r[200005], outfx[200005] , dp[200005][505];
vector<int> adj[200005];
int n , m , time = 0;
int root = -1;
int in[200005] , out[200005];
void solve(int x , int y){
in[x] = ++time;
r[in[x]] = c[x];
dp[in[x]][1] = c[x];
for(auto p : adj[x]){
if(p == y) continue;
solve(p, x);
}
out[in[x]] = time;
}
int32_t main(){
scanf("%d%d" ,&n , &m);
for(int i = 1 ; i <= n; i ++){
int x , y;
scanf("%d%d" , &x , &y);
c[i] = y;
if(x == 0) root = i;
else{
adj[x].pb(i);
adj[i].pb(x);
}
}
solve(root, root);
int ans = 0;
for(int i = time ; i >= 1 ; i--){
for(int j = 1 ; j <= m ; j++){
if(out[i] + 1 <= time){
dp[i][j] = max(dp[i][j] , dp[out[i] + 1][j-1] + r[i]);
}
if(j == m) ans = max(ans , dp[i][j]);
}
}
printf("%d\n" , ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |