# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97436 | 2019-02-16T05:25:15 Z | aquablitz11 | Biochips (IZhO12_biochips) | C++14 | 204 ms | 12380 KB |
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int M = 510; vector<int> G[N]; int val[N], dp[2][N]; int ip[N], idx[N], nxt[N], tim; void dfs(int u) { int p = ++tim; idx[p] = u; ip[p] = val[u]; for (auto v : G[u]) dfs(v); nxt[p] = tim+1; } int main() { int n, m; scanf("%d%d", &n, &m); int r = 0; for (int i = 1; i <= n; ++i) { int p; scanf("%d%d", &p, &val[i]); if (p) G[p].push_back(i); else r = i; } dfs(r); /*for (int i = 1; i <= n; ++i) printf("%d ", idx[i]); printf("\n"); for (int i = 1; i <= n; ++i) printf("%d ", nxt[i]); printf("\n"); for (int i = 1; i <= n; ++i) printf("%d ", ip[i]); printf("\n");*/ for (int i = 1; i <= m; ++i) { int x = i&1; int p = x^1; dp[x][n+1] = -(2e9+1); for (int j = n; j >= 1; --j) dp[x][j] = max(dp[x][j+1], dp[p][nxt[j]]+ip[j]); } printf("%d\n", dp[m&1][1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5320 KB | Output is correct |
2 | Correct | 7 ms | 4992 KB | Output is correct |
3 | Correct | 7 ms | 4992 KB | Output is correct |
4 | Correct | 13 ms | 5496 KB | Output is correct |
5 | Correct | 13 ms | 5496 KB | Output is correct |
6 | Correct | 13 ms | 5500 KB | Output is correct |
7 | Correct | 132 ms | 11004 KB | Output is correct |
8 | Correct | 159 ms | 11260 KB | Output is correct |
9 | Correct | 180 ms | 11868 KB | Output is correct |
10 | Correct | 204 ms | 12380 KB | Output is correct |