Submission #30848

#TimeUsernameProblemLanguageResultExecution timeMemory
30848KerimBiochips (IZhO12_biochips)C++14
100 / 100
389 ms12452 KiB
#include "bits/stdc++.h" #define MAXN 200009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} int arr[MAXN],go[MAXN],cost[MAXN],dp[2][MAXN],TIM,id[MAXN]; vector<int>adj[MAXN]; void dfs(int nd){ int tm=++TIM; id[tm]=nd; tr(it,adj[nd]) dfs(*it); go[tm]=TIM; } int main(){ //~ #ifndef ONLINE_JUDGE //~ freopen("file.in", "r", stdin); //~ #endif int n,m,root; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ int p; scanf("%d%d",&p,&arr[i]); if(p) adj[p].pb(i); else root=i; }dfs(root); for(int i=1;i<=n;i++) dp[1][i]=arr[id[i]]; for(int i=2;i<=m;i++){cost[n+1]=-INF; for(int j=n;j>=1;j--) cost[j]=max(cost[j+1],dp[(i-1)&1][j]); for(int j=n;j>=1;j--) dp[i&1][j]=cost[go[j]+1]+arr[id[j]]; } int ans=0; for(int i=1;i<=n;i++) umax(ans,dp[m&1][i]); printf("%d\n",ans) ; return 0; }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
biochips.cpp:37:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&p,&arr[i]);
                           ^
biochips.cpp:42:12: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
  }dfs(root);
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...