# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092446 | juicy | 바이오칩 (IZhO12_biochips) | C++17 | 293 ms | 400208 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, m;
int a[N], L[N], R[N], pos[N], dp[N][502];
vector<int> g[N];
int timer;
void dfs(int u) {
pos[L[u] = ++timer] = u;
for (int v : g[u]) {
dfs(v);
}
R[u] = timer;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
int rt = -1;
for (int i = 1; i <= n; ++i) {
int pr; cin >> pr >> a[i];
if (!pr) {
rt = i;
} else {
g[pr].push_back(i);
}
}
dfs(rt);
for (int i = 1; i <= n; ++i) {
int u = pos[i];
for (int j = 0; j <= m; ++j) {
dp[R[u] + 1][j + 1] = max(dp[R[u] + 1][j + 1], dp[i][j] + a[u]);
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n + 1][m];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |