Submission #310762

#TimeUsernameProblemLanguageResultExecution timeMemory
310762ly20Chase (CEOI17_chase)C++17
30 / 100
182 ms101368 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 112345, MAXK = 112; vector <int> grafo[MAXN]; long long val[MAXN], vz[MAXN], dp[MAXN][MAXK]; int n, k; long long resp; void dfs(int v, int p) { for(int i = 0; i <= k; i++) resp = max(resp, dp[v][i]); for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(viz == p) continue; dp[viz][0] = 0; for(int j = 1; j <= k; j++) { dp[viz][j] = max(dp[v][j], dp[v][j - 1] + vz[viz] - val[v]); } dfs(viz, v); } } int main() { scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) { scanf("%lld", &val[i]); } for(int i = 0; i < n - 1; i++) { int a, b; scanf("%d %d", &a, &b); grafo[a].push_back(b); grafo[b].push_back(a); vz[a] += val[b]; vz[b] += val[a]; } int i = 1; dp[i][0] = 0; for(int j = 1; j <= k; j++) dp[i][j] = vz[i]; dfs(i, 0); printf("%lld\n", resp); return 0; }

Compilation message (stderr)

chase.cpp: In function 'void dfs(int, int)':
chase.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
chase.cpp: In function 'int main()':
chase.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
chase.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf("%lld", &val[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
chase.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...