# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
876385 | dilanyan | Biochips (IZhO12_biochips) | C++17 | 2086 ms | 274980 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const int mod = 1000000007;
const ll inf = 2e9;
//-------------------KarginCode------------------------\\
const int N = 200005;
int c[N], dp[N][505], s[N];
vector<int> g[N];
int t = 0, n, m;
void dfs(int u) {
s[u]++;
for (int v : g[u]) {
dfs(v);
s[u] += s[v];
for (int i = min(m, s[u]);i >= 0;--i) {
for (int j = 0;j <= min(m - i, s[u]);++j) {
dp[u][i + j] = max(dp[u][i + j], dp[u][i] + dp[v][j]);
}
}
}
dp[u][1] = max(dp[u][1], c[u]);
}
void KarginSolve() {
cin >> n >> m;
int root = 0;
for (int i = 1; i <= n;++i) {
int p;
cin >> p >> c[i];
if (p == 0) root = i;
else g[p].pb(i);
}
dfs(root);
cout << dp[root][m] << '\n';
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |