Submission #106694

# Submission time Handle Problem Language Result Execution time Memory
106694 2019-04-19T17:31:40 Z Pajaraja Biochips (IZhO12_biochips) C++17
0 / 100
8 ms 5120 KB
#include <bits/stdc++.h>
#define MAXN 200007
using namespace std;
vector<int> g[MAXN];
int w[MAXN],dp[MAXN],dpp[MAXN],nz[MAXN],dk[MAXN],t,wn[MAXN];
void dfs(int s)
{
	int in=t;
	for(int i=0;i<g[s].size();i++) dfs(g[s][i]);
	dk[++t]=in; wn[t]=w[s];
}
int main()
{
	int n,m,rt;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int p; scanf("%d%d",&p,&w[i]);
		if(p==0) rt=i;
		else g[p].push_back(i);
	}
	dfs(rt); dp[0]=-1000000000; dpp[0]=-1000000000;
	for(int i=1;i<=n;i++) dpp[i]=wn[i];
	for(int k=1;k<m;k++)
	{
		for(int i=1;i<=n;i++) dp[i]=max(dpp[dk[i]]+wn[i],dp[i-1]);
		for(int i=1;i<=n;i++) dpp[i]=dp[i];
	}
	printf("%d",dp[n]);
}

Compilation message

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:9:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[s].size();i++) dfs(g[s][i]);
              ~^~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
biochips.cpp:18:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int p; scanf("%d%d",&p,&w[i]);
          ~~~~~^~~~~~~~~~~~~~~~~
biochips.cpp:22:5: warning: 'rt' may be used uninitialized in this function [-Wmaybe-uninitialized]
  dfs(rt); dp[0]=-1000000000; dpp[0]=-1000000000;
  ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Incorrect 8 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -