Submission #86867

#TimeUsernameProblemLanguageResultExecution timeMemory
86867Just_Solve_The_ProblemBiochips (IZhO12_biochips)C++11
0 / 100
4 ms1912 KiB
#include <iostream> #include <bitset> #include <algorithm> #include <memory.h> #include <utility> #include <vector> #include <cmath> #include <math.h> #include <time.h> #include <assert.h> #include <map> #include <queue> #define int long long using namespace std; const int N = (int)200 + 1; const int M = (int)500 + 1; const int inf = (int)1e9 + 7; int n; int pr[N], w[N]; int root; int dp[N][M]; int dpg[N][M]; int prv[N], lst[N]; int f(int, int); int g(int, int); int g(int v, int m) { if (m == 0) return 0; if (v < 0) { if (m != 0) { return -inf; } else { return 0; } } int &res = dpg[v][m]; if (res != -1) return res; res = -inf; for (int j = 0; j <= m; j++) { res = max(res, f(v, j) + g(prv[v], m - j)); } //cout << "g -> " << v << ' ' << m << ' ' << res << endl; return res; } int f(int v, int m) { int &res = dp[v][m]; if (res != -1) return res; res = -inf; if (m == 0) { return res = 0; } if (lst[v] == -1) { if (m == 1) return res = w[v]; return res = -inf; } if (m == 1) { res = max(w[v], g(lst[v], m)); } else { res = g(lst[v], m); } //cout << "f -> " << v << ' ' << m << ' ' << res << endl; return res; } main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m; memset(dp, -1, sizeof dp); memset(dpg, -1, sizeof dpg); memset(lst, -1, sizeof lst); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> pr[i] >> w[i]; if (!pr[i]) { root = i; } else { prv[i] = lst[pr[i]]; lst[pr[i]] = i; } } prv[root] = -1; cout << f(root, m); }

Compilation message (stderr)

biochips.cpp:72:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...