# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41325 | 2018-02-16T04:54:59 Z | wzy | Biochips (IZhO12_biochips) | C++14 | 5 ms | 4984 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back int dp[200005][505] , c[200005] , n ,m; vector<int> adj[200005]; int st[200005] , rv[200005] , ed[200005] , t = -1; int root = -1; void dfs(int x , int y){ st[x] = ++t; for(int i = 0 ; i < adj[x].size() ; i++){ int v = adj[x][i]; if(y == v) continue; dfs(v , x); } ed[st[x]] = t; rv[st[x]] = x; } int main(){ scanf("%d%d" , &n , &m); for(int i = 0 ; i <n;i++){ int x , cy; scanf("%d%d" , &x , &cy); c[i] = cy; if(x == 0){ root = i; continue; } adj[i].pb(x-1); adj[x-1].pb(i); } dfs(root , root); for(int i = 0 ; i<= n ;i++) for(int j = 0 ; j <= m; j++) dp[i][j] = -100000000; dp[0][0] = 0; dp[1][ed[0]] = c[root]; for(int i = 1 ; i <n ; i++){ for(int j = 1 ; j <= m ; j++){ int wut = 0; if(i) wut = dp[j-1][i-1]; dp[j][ed[i]] = max(dp[j][ed[i]] , wut + c[rv[i]]); } } printf("%d\n" , dp[m][n-1]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 4984 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |