# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41118 | 2018-02-13T02:28:08 Z | wzy | Biochips (IZhO12_biochips) | C++14 | 289 ms | 400292 KB |
#include <stdio.h> #include <stdint.h> #include <string.h> #include <vector> #include <algorithm> #include <utility> using namespace std; #define eps (int) 1e9 #define pb push_back int root , rv[200005], t = 0 , dp[200005][505] , c[200005] , n , m , st[200005] , ed[200005]; vector<int> adj[200005]; void dfs(int x , int y){ st[x] = ++t; rv[st[x]] = x; for(int i = 0 ; i < adj[x].size() ; i++){ int v = adj[x][i]; if(v == y) continue; dfs(v,x); } ed[x] = t; return; } int solve(int i, int j){ if(dp[i][j] != -1) return dp[i][j]; if(j > m || i > t ) return -eps; if(j == m) return 0; if(i > t) return - eps; dp[i][j] = 0; return dp[i][j] = max(solve(i + 1 , j) , solve(ed[rv[i]] + 1 , j + 1) + c[rv[i]]); } int32_t main(){ scanf("%d%d" , &n , &m); for(int i = 0 ; i <n; i++){ int x , y; scanf("%d%d" , &x, &y); c[i] = y; if(x == 0){ root = i; continue; } else{ adj[i].pb(x-1); adj[x-1].pb(i); } } dfs(root, root); memset(dp , -1 , sizeof dp); int qq = solve(st[root] , 0); printf("%d\n" , qq); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 289 ms | 400292 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |