# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
715188 | MilosMilutinovic | 바이오칩 (IZhO12_biochips) | C++14 | 838 ms | 400208 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: wxhtzdy
* created: 26.03.2023 09:30:33
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> x(n);
vector<vector<int>> g(n);
int root;
for (int i = 0; i < n; i++) {
int p;
cin >> p >> x[i];
--p;
if (p == -1) {
root = i;
} else {
g[p].push_back(i);
g[i].push_back(p);
}
}
vector<vector<int>> dp(n, vector<int>(m + 1));
vector<int> sz(n);
function<void(int, int)> Dfs = [&](int v, int pv) {
for (int u : g[v]) {
if (u == pv) {
continue;
}
Dfs(u, v);
for (int i = min(m, sz[v]); i >= 0; i--) {
for (int j = min(m - i, sz[u]); j >= 0; j--) {
dp[v][i + j] = max(dp[v][i + j], dp[v][i] + dp[u][j]);
}
}
sz[v] += sz[u];
}
sz[v] += 1;
dp[v][1] = max(dp[v][1], x[v]);
};
Dfs(root, root);
cout << dp[root][m] << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |