답안 #827435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827435 2023-08-16T13:13:49 Z MasterTaster 바이오칩 (IZhO12_biochips) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 22//200010
#define MAXM 22//510
#define MAXX 100000010

using namespace std;

int n, m, p[MAXN], w[MAXN], dp[MAXN][MAXM];
bool bio[MAXN];
vector<int> g[MAXN];

void merge(int u, int v)
{
	int pomoc[MAXM];
	for (int i=0; i<=m; i++) pomoc[i]=dp[u][i];

	for (int i=0; i<=m; i++)
		for (int j=0; i+j<=m; j++)
			if (i+j<=m) pomoc[i+j]=max(pomoc[i+j], dp[u][i]+dp[v][j]);

	for (int i=0; i<=m; i++) dp[u][i]=pomoc[i];
}

void dfs(int u)
{
	bio[u]=true;

	for (int i=0; i<=m; i++) dp[u][i]=-MAXX;
	dp[u][0]=0;

	for (auto v:g[u])
	{
		if (!bio[v])
		{
			dfs(v);
		}
	}

	for (auto v:g[u])
	{
		if (v==p[u]) continue;
		merge(u, v);
	}
	dp[u][1]=max(dp[u][1], w[u]);

	///cout<<u<<":"<<endl;
	///for (int i=0; i<=m; i++) cout<<dp[u][i]<<" ";
	///cout<<endl;
}

int main(){

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	cin>>n>>m;

	int koren=1;
	for (int i=1; i<=n; i++)
	{
		cin>>p[i]>>w[i];
		if (p[i]==0) { koren=i; continue; }
		g[p[i]].pb(i); g[i].pb(p[i]);
	}

	dfs(koren);

	cout<<dp[koren][m];
}

///-10 bar

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:60:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:61:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Incorrect 0 ms 212 KB Output isn't correct