# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
685243 | Ronin13 | 바이오칩 (IZhO12_biochips) | C++14 | 567 ms | 397144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 2e5 + 1;
vector <vector <int> > g(nmax);
int dp[nmax][501];
vector <int> a(nmax);
int ans = 0;
int last;
int m;
void dfs(int v, int e = -1){
for(int j= 500; j >= 1; j--){
dp[v][j] = max(dp[v][j], dp[last][j - 1] + a[v]);
dp[v][j] = max(dp[v][j], dp[last][j]);
}
ans = max(ans, dp[v][m]);
for(int to : g[v]){
if(to == e) continue;
dfs(to, v);
}
for(int j = 500; j >= 1; j--){
dp[v][j] = max(dp[v][j], dp[last][j]);
}
last = v;
}
int main(){
int n; cin >> n;
cin >> m;
int root = 0;
for(int i = 1; i <= n; i++){
int x; cin >> x;
g[x].pb(i);
if(!x) root = i;
cin >> a[i];
}
for(int i = 1; i <= 500; i++)
dp[0][i] = -1e9;
dfs(root);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |