Submission #684999

#TimeUsernameProblemLanguageResultExecution timeMemory
684999saayan007Biochips (IZhO12_biochips)C++14
20 / 100
121 ms9032 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]; fur(i, 0, k) { fur(j, 0, m) { a[i][j] = -inf; } } a[0][0] = 0; fur(x, 1, k) { a[x][0] = 0; fur(y, 1, m) { fur(z, 0, y) { a[x][y] = max(a[x][y], dp[adj[cur][x - 1]][z] + a[x - 1][y - z]); } } } fur(j, 2, m) { dp[cur][j] = a[k][j]; } dp[cur][0] = 0; dp[cur][1] = max(s[cur], one); } 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; } } // cout << "Adj List\n"; // fur(i, 1, n) { // cout << i << " : "; // for(auto u : adj[i]) // cout << u << ' '; // cout << nl; // } // cout <<nl; fur(i, 0, n) { fur(j, 0, m) { // dp[i][j] = a[i][j] = -inf; dp[i][j] = -inf; } } // cout << "L, R\n"; dfs(root, -1); // fur(i, 1, n) { // cout << l[i] << ' ' << r[i] << nl; // } // cout << nl; // fur(i, 1, n) { // fur(j, 0, m) { // if(dp[i][j] < 0) { // cout << " -"; // } else // cout << dp[i][j] << ' '; // } // cout << nl; // } 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...