Submission #1201425

#TimeUsernameProblemLanguageResultExecution timeMemory
1201425CrabCNH바이오칩 (IZhO12_biochips)C++20
60 / 100
13 ms11404 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) using namespace std; template <class T> void mini (T &t, T f) {if (t > f) t = f;} template <class T> void maxi (T &t, T f) {if (t < f) t = f;} const int maxN = 1e5 + 5; const int maxM = 1e2 + 5; const int inf = 1e3 + 7; const int mod = 1e9 + 7; int n, m, rt; int c[maxN], sz[maxN]; vector <int> adj[maxN]; int dp[maxN][maxM]; void dfs (int u, int p) { sz[u] = 1; dp[u][0] = 0; for (auto v : adj[u]) { if (v == p) { continue; } dfs (v, u); for (int j = sz[u]; j >= 0; j --) { for (int k = min (sz[v], m - j); k >= 0; k --) { maxi (dp[u][j + k], dp[u][j] + dp[v][k]); } } sz[u] += sz[v]; } maxi (dp[u][1], c[u]); // for (int i = 0; i <= sz[u]; i ++) { // cout << u << ' ' << dp[u][i] << '\n'; // } } void solve () { cin >> n >> m; for (int i = 1; i <= n; i ++) { int p; cin >> p >> c[i]; if (p != 0) { adj[p].push_back (i); adj[i].push_back (p); //cout << i << ' ' << p << '\n'; } else { rt = i; } } for (int i = 1; i <= n; i ++) { for (int j = 0; j <= m; j ++) { dp[i][j] = -inf; } } dfs (rt, rt); cout << dp[rt][m]; } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { solve (); } return 0; } // thfdgb

Compilation message (stderr)

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