//-------------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) {
if (g[u].empty()) dp[u][1] = c[u], s[u]++;
for (int v : g[u]) {
dfs(v);
s[u] += s[v];
for (int i = 1;i <= min(s[u], m);++i) {
for (int j = i;j >= 0;--j) {
dp[u][i] = max(dp[u][i], dp[u][i - j] + dp[v][j]);
}
}
}
}
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
biochips.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
biochips.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
biochips.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
biochips.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
6800 KB |
Output isn't correct |
4 |
Incorrect |
9 ms |
25436 KB |
Output isn't correct |
5 |
Incorrect |
10 ms |
27532 KB |
Output isn't correct |
6 |
Incorrect |
9 ms |
25944 KB |
Output isn't correct |
7 |
Execution timed out |
2061 ms |
302008 KB |
Time limit exceeded |
8 |
Execution timed out |
2051 ms |
301264 KB |
Time limit exceeded |
9 |
Execution timed out |
2033 ms |
364888 KB |
Time limit exceeded |
10 |
Execution timed out |
2017 ms |
404108 KB |
Time limit exceeded |