Submission #146745

# Submission time Handle Problem Language Result Execution time Memory
146745 2019-08-25T20:10:13 Z abacaba Biochips (IZhO12_biochips) C++14
100 / 100
1000 ms 399560 KB
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 2e5 + 1;
const int M = 5e2 + 1;
int n, m, a[N], root, sz[N], dp[N][M];
vector <int> g[N];

void dfs(int v) {
	sz[v] = 1;
	for(int to : g[v]) {
		dfs(to);
		sz[v] += sz[to];
	}
	for(int to : g[v])
		for(int i = min(m, sz[v] + sz[to]); i >= 1; --i) {
			for(int j = 1; j <= min(m, sz[to]) && j < i; ++j)
				if(dp[v][i - j] && dp[to][j])
					dp[v][i] = max(dp[v][i], dp[v][i - j] + dp[to][j]);
				dp[v][i] = max(dp[v][i], dp[to][i]);
			}
	dp[v][1] = max(a[v], dp[v][1]);
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) {
		int x;
		scanf("%d%d", &x, &a[i]);
		if(!x)
			root = i;
		else
			g[x].pb(i);
	}
	dfs(root);
	printf("%d\n", dp[root][m]);
	return 0;
}

Compilation message

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:46:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for(int j = 1; j <= min(m, sz[to]) && j < i; ++j)
    ^~~
biochips.cpp:49:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     dp[v][i] = max(dp[v][i], dp[to][i]);
     ^~
biochips.cpp: In function 'int main()':
biochips.cpp:55: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:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &a[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 5240 KB Output is correct
4 Correct 33 ms 22776 KB Output is correct
5 Correct 36 ms 24952 KB Output is correct
6 Correct 36 ms 24952 KB Output is correct
7 Correct 607 ms 297992 KB Output is correct
8 Correct 622 ms 298016 KB Output is correct
9 Correct 813 ms 362056 KB Output is correct
10 Correct 1000 ms 399560 KB Output is correct