제출 #236404

#제출 시각아이디문제언어결과실행 시간메모리
236404mahmoudbadawy바이오칩 (IZhO12_biochips)C++17
100 / 100
695 ms402296 KiB
#include <bits/stdc++.h>

using namespace std;

const int N=2e5+5;

vector<int> adj[N];
int arr[N],dp[N][505];
int n,m;

void dfs(int node)
{
	int tmp[505];
	for(int u:adj[node])
	{
		dfs(u);
		for(int i=0;i<=m;i++) tmp[i]=0;
		for(int i=0;i<=m;i++)
		{
			if(i&&dp[node][i]==0) break;
			for(int j=1;i+j<=m;j++)
			{
				if(dp[u][j]==0) break;
				tmp[i+j]=max(tmp[i+j],dp[node][i]+dp[u][j]);
			}
		}
		for(int i=0;i<=m;i++) dp[node][i]=max(dp[node][i],tmp[i]);
	}
	dp[node][1]=max(dp[node][1],arr[node]);
}

int main()
{
	scanf("%d %d",&n,&m);
	int root=-1;
	for(int i=1;i<=n;i++)
	{
		int pa;
		scanf("%d %d",&pa,&arr[i]);
		if(pa) adj[pa].push_back(i);
		else root=i;
	}
	dfs(root);
	cout << dp[root][m] << endl;
	/*for(int x=1;x<=n;x++)
	{
		for(int i=0;i<=m;i++)
			cout << dp[x][i] << " ";
		cout << endl;
	}*/
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

biochips.cpp: In function 'int main()':
biochips.cpp:34: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:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&pa,&arr[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...