# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095080 | 2024-10-01T08:32:19 Z | Sunbae | Biochips (IZhO12_biochips) | C++17 | 355 ms | 13916 KB |
#include <bits/stdc++.h> #define z exit(0) typedef long long ll; using namespace std; const int N = 2e5 + 5; vector<int> g[N]; ll a[N]; vector<ll> cur, nxt; int invp[N], jump[N], ti; void dfs(int u){ int pre = ti++; invp[pre] = u; for(int v: g[u]) dfs(v); jump[pre] = ti; } signed main(){ int n, K, rt; scanf("%d %d", &n, &K); for(int v = 0, u; v<n; ++v){ scanf("%d %lld", &u, a+v); if(--u >= 0) g[u].push_back(v); else rt = v; } dfs(rt); cur.resize(n+1); nxt.resize(n+1); fill(cur.begin(), cur.end(), INT_MIN); cur[0] = 0; for(int k = 0; k<K; ++k){ fill(nxt.begin(), nxt.end(), INT_MIN); for(int i = 0; i<n; ++i){ cur[i+1] = max(cur[i+1], cur[i]); nxt[jump[i]] = max(nxt[jump[i]], cur[i] + a[invp[i]]); } cur = nxt; } printf("%lld", *max_element(cur.begin(), cur.end())); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4956 KB | Output is correct |
2 | Correct | 2 ms | 4956 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 5 ms | 5468 KB | Output is correct |
5 | Correct | 6 ms | 5468 KB | Output is correct |
6 | Correct | 6 ms | 5668 KB | Output is correct |
7 | Correct | 196 ms | 12376 KB | Output is correct |
8 | Correct | 164 ms | 12372 KB | Output is correct |
9 | Correct | 293 ms | 13112 KB | Output is correct |
10 | Correct | 355 ms | 13916 KB | Output is correct |