# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
162584 | darkkcyan | 바이오칩 (IZhO12_biochips) | C++14 | 385 ms | 13240 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;
#define llong long long
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
// #define rand __rand
// mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // or mt19937_64
// template<class T = int> T rand(T range = numeric_limits<T>::max()) {
// return (T)(rng() % range);
// }
#define maxn 200010
int n, m;
int a[maxn];
vector<int> gr[maxn];
vector<int> topo_a, prev_pos;
void dfs(int u) {
int t = len(topo_a);
for (auto v: gr[u]) {
dfs(v);
}
topo_a.push_back(a[u]);
prev_pos.push_back(t);
}
llong dp[2][maxn];
int main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
rep1(i, n) {
int p; cin >> p >> a[i];
gr[p].push_back(i);
}
dfs(0);
memset(dp[0], 0, sizeof dp[0]);
rep1(i, m) {
dp[i & 1][0] = INT_MIN;
rep(u, n) {
dp[i & 1][u + 1] = max(dp[i & 1][u], dp[~i & 1][prev_pos[u]] + topo_a[u]);
}
}
cout << dp[m & 1][n];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |