Submission #685001

#TimeUsernameProblemLanguageResultExecution timeMemory
685001saayan007Biochips (IZhO12_biochips)C++14
10 / 100
118 ms9016 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pi>; using vpl = vector<pl>; #define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i) #define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i) #define fr first #define sc second #define mp make_pair #define pb push_back #define nl "\n" #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const ll mxn = 1e4L; const ll mxm = 1e2L; #warning mxn, mxm are set wrong const ll inf = 1e12L; ll n, m; ll root; ll p[mxn + 1]; vl adj[mxn + 1]; ll s[mxn + 1]; ll dp[mxn + 1][mxm + 1]; void dfs(ll cur, ll par) { ll one = -inf; for(auto u : adj[cur]) { if(u == par) continue; dfs(u, cur); one = max(one, dp[u][1]); } ll k = adj[cur].size(); ll a[k + 1][m + 1]; a[0][0] = 0; fur(y, 1, m) { a[0][y] = -inf; } fur(x, 1, k) { a[x][0] = 0; fur(y, 1, m) { a[x][y] = -inf; fur(z, 0, y) { a[x][y] = max(a[x][y], dp[adj[cur][x - 1]][z] + a[x - 1][y - z]); } } } dp[cur][0] = 0; dp[cur][1] = max(s[cur], dp[cur][1]); fur(j, 2, m) { dp[cur][j] = a[k][j]; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; fur(i, 1, n) { cin >> p[i] >> s[i]; if(p[i] != 0) { adj[i].pb(p[i]); adj[p[i]].pb(i); } else { root = i; } } fur(i, 0, n) { fur(j, 0, m) { dp[i][j] = -inf; } } dfs(root, -1); cout << dp[root][m] << nl; }

Compilation message (stderr)

biochips.cpp:24:2: warning: #warning mxn, mxm are set wrong [-Wcpp]
   24 | #warning mxn, mxm are set wrong
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...