Submission #359937

# Submission time Handle Problem Language Result Execution time Memory
359937 2021-01-27T10:39:48 Z Fischer Biochips (IZhO12_biochips) C++14
0 / 100
4 ms 4972 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int dp[maxn][510];
vector<int> g[maxn];
int c[maxn];
int sz[maxn];
int n, m;
void dfs(int x) {
	sz[x] = 0;
	for (int i = 1; i <= m; ++i) dp[x][i] = -1e9;
	for (int v : g[x]) {
		dfs(v);
		for (int i = min(m, sz[x] + sz[v]); i >= 1; --i) {
			for (int j = max(1, i - sz[x]); j <= min(m, sz[v]); ++j) {
				dp[x][i] = max(dp[x][i], dp[x][i - j] + dp[v][j]);
			}
		}
		sz[x] += sz[v];
	}
	sz[x] += 1;
	dp[x][1] = max(dp[x][1], c[x]);
}

int main() {
	freopen("d.in", "r", stdin);
	freopen("d.out", "w", stdout);
	cin >> n >> m;
	int root = 0;
	for (int i = 1; i <= n; ++i) {
		int pi;
		cin >> pi >> c[i];
		if (pi == 0) root = i;
		else g[pi].push_back(i);
	}
	dfs(root);
	cout << dp[root][m] << endl;
	return 0;
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:27:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  freopen("d.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:28:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |  freopen("d.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4972 KB Output isn't correct
2 Halted 0 ms 0 KB -