Submission #490788

#TimeUsernameProblemLanguageResultExecution timeMemory
490788ntabc05101Biochips (IZhO12_biochips)C++14
0 / 100
63 ms8980 KiB
#include<bits/stdc++.h> using namespace std; #define taskname "" const long long inf = 1e18; const int mxN = 10002; const int mxM = 102; int n, m; int a[mxN]; vector<int> adj[mxN]; long long dp[mxN][mxM]; void dfs(int u, int p = -1) { for (int i = 1; i <= m; i++) { dp[u][i] = -inf; } for (auto &to: adj[u]) { if (to != p) { dfs(to, u); for (int k = m; k; k--) { for (int j = 1; j <= k; j++) { dp[u][k] = max(dp[u][k], dp[u][k - j] + dp[to][j]); } } } } dp[u][1] = max(dp[u][1], (long long)a[u]); /*cout << 1 + u << ":\n"; for (int i = 0; i <= m; i++) { cout << dp[u][i] << " "; } cout << "\n";*/ } int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } else { if (fopen(taskname".in", "r")) { freopen(taskname".in", "r", stdin); freopen(taskname".out", "w", stdout); } } cin.tie(0)->sync_with_stdio(0); cin >> n >> m; int root = -1; for (int i = 0, x, y; i < n; i++) { cin >> x >> y; x--; a[i] = y; if (!(~x)) { root = i; continue; } adj[x].push_back(i); adj[i].push_back(x); } dfs(root); cout << dp[root][m] << "\n"; return 0; }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:41:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   freopen(taskname".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:45:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |    freopen(taskname".in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:46:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    freopen(taskname".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...