| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 954123 | adaawf | 바이오칩 (IZhO12_biochips) | C++17 | 513 ms | 403664 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[200005];
int f[200005][505], a[200005], k;
void dfs(int x) {
for (int w : g[x]) {
dfs(w);
for (int i = k; i >= 0; i--) {
for (int j = 0; j <= k - i; j++) {
if (j != 0 && f[w][j] == 0) break;
f[x][i + j] = max(f[x][i + j], f[x][i] + f[w][j]);
}
}
}
f[x][1] = max(f[x][1], a[x]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, r = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
a[i] = y;
if (x == 0) {
r = i;
}
else {
g[x].push_back(i);
}
}
dfs(r);
cout << f[r][k];
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
