# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334679 | 2020-12-09T18:32:58 Z | iulia13 | Biochips (IZhO12_biochips) | C++14 | 917 ms | 390652 KB |
#include <iostream> #include <deque> #include <vector> using namespace std; int dp[505][200005]; vector <int> g[200005]; int v[200005]; int in[200005]; int ord[400005]; int out[400005]; int eul[400005]; int timp = 0; void dfs(int nod) { timp++; in[nod] = timp; ord[timp] = nod; dp[1][timp] = v[nod]; for (int i = 0; i < g[nod].size(); i++) { int x = g[nod][i]; dfs(x); } out[in[nod]] = timp; } int main() { int n, m, i, j, r, k, l, x; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> x >> v[i]; if (x) g[x].push_back(i); else r = i; } dfs(r); int ans = 0; for (j = 1; j <= m; j++) for (i = timp; i; i--) { dp[j][i] = max(dp[j][i], dp[j][i + 1]); int last = out[i] + 1; if (last <= timp) dp[j][i] = max(dp[j][i], dp[j - 1][last] + v[ord[i]]); if (j == m) ans = max(ans, dp[m][i]); } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5100 KB | Output is correct |
2 | Correct | 4 ms | 5100 KB | Output is correct |
3 | Correct | 4 ms | 5100 KB | Output is correct |
4 | Correct | 14 ms | 7788 KB | Output is correct |
5 | Correct | 16 ms | 8812 KB | Output is correct |
6 | Correct | 18 ms | 9836 KB | Output is correct |
7 | Correct | 456 ms | 183168 KB | Output is correct |
8 | Correct | 456 ms | 183148 KB | Output is correct |
9 | Correct | 665 ms | 286772 KB | Output is correct |
10 | Correct | 917 ms | 390652 KB | Output is correct |