Submission #867463

#TimeUsernameProblemLanguageResultExecution timeMemory
867463sleepntsheepBiochips (IZhO12_biochips)C++17
30 / 100
56 ms40536 KiB
#include <iostream> #include <cstring> #include <cassert> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> using namespace std; #define ALL(x) x.begin(), x.end() #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); #define N 200050 using ll = long long; int n, m, a[N], timer, dp[2][N], in[N], dp2[501][N], sz[N], hi[N]; vector<int> g[N], g2[N]; vector<tuple<int, int, int>> v; void dfs1(int u) { ++sz[u]; for (auto v : g[u]) { dfs1(v); for (int i = sz[u]; i--;) for (int j = 0; j <= sz[v]; ++j) dp2[i+j][u] = max(dp2[i+j][u], dp2[i][u] + dp2[j][v]); sz[u] += sz[v]; } dp2[1][u] = max(dp2[1][u], a[u]); } int main() { ShinLena; cin >> n >> m; for (int p, i = 1; i <= n; ++i) cin >> p >> a[i], g[p].push_back(i); dfs1(0); cout << dp2[m][0]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...