# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
583041 | 2022-06-24T17:53:39 Z | 600Mihnea | Chase (CEOI17_chase) | C++17 | 3 ms | 2644 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = (int) 1e5 + 7; const int B = 100 + 7; const ll INF = (ll) 1e18 + 7; int n, bread_have, pigs[N]; ll gain[N]; ll dp[N][B]; vector<int> g[N]; void dfs(int a, int p = 0) { for (int i = 0; i <= bread_have; i++) { dp[a][i] = 0; } gain[a] = 0; for (auto &b : g[a]) { if (b != p) { dfs(b, a); gain[a] += pigs[b]; for (int i = 1; i <= bread_have; i++) { dp[a][i] = max(dp[a][i], dp[b][i]); } } } for (int i = bread_have - 1; i >= 0; i--) { dp[a][i + 1] = max(dp[a][i + 1], dp[a][i] + gain[a]); } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen ("input.txt", "r", stdin); cin >> n >> bread_have; for (int i = 1; i <= n; i++) { cin >> pigs[i]; } for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } ll sol = -INF; for (int root = 1; root <= n; root++) { dfs(root); for (int i = 1; i <= bread_have; i++) { assert(dp[root][i - 1] <= dp[root][i]); } sol = max(sol, dp[root][bread_have]); } cout << sol << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |