Submission #310431

#TimeUsernameProblemLanguageResultExecution timeMemory
310431pedroslreyChase (CEOI17_chase)C++14
40 / 100
4035 ms98808 KiB
#include <bits/stdc++.h> using namespace std; using lli = long long int; const int MAXN = 100010; const int MAXM = 110; #define debug(args...) //fprintf(stderr, args); int n, m; lli ps[MAXN]; lli dp[MAXN][MAXM]; vector<int> graph[MAXN]; void dfs(int v, int p) { lli sum = 0; for (int u: graph[v]) { if (u == p) continue; sum +=ps[u]; dfs(u, v); } for (int k = 0; k <= m; k++) { dp[v][k] = 0; for (int u: graph[v]) { if (u == p) continue; dp[v][k] = max(dp[v][k], dp[u][k]); if (k) dp[v][k] = max(dp[v][k], dp[u][k - 1] + sum); } } debug("dp[%d][%d] = %d\n", v, m, dp[v][m]); } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%lld", &ps[i]); for (int i = 0; i < n-1; ++i) { int u, v; scanf("%d %d", &u, &v); graph[u].push_back(v); graph[v].push_back(u); } lli ans = 0; for (int i = 1; i <= n; ++i) { dfs(i, i); debug("OI\n"); for (int j = 1; j <= n; ++j) ans = max(ans, dp[j][m]); } printf("%lld\n", ans); }

Compilation message (stderr)

chase.cpp: In function 'int main()':
chase.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
chase.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |   scanf("%lld", &ps[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~
chase.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...