# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
945083 | 2024-03-13T11:39:25 Z | vjudge1 | Chase (CEOI17_chase) | C++17 | 101 ms | 91220 KB |
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <cstring> #warning That's the baby, that's not my baby typedef long long ll; const int NMAX = 1e5; const int VMAX = 100; ll dp[NMAX + 1][VMAX + 1]; int a[NMAX + 1]; int V; std::vector<int> g[NMAX + 1]; void dfs(int u, int p = 0) { ll s = 0; for (const auto &v : g[u]) { if (v != p) { dfs(v, u); s += a[v]; } } for (const auto &v : g[u]) { if (v != p) { for (int i = 0; i <= V; i++) { if (i != 0) { dp[u][i] = std::max(dp[u][i], s + std::max(0LL, dp[v][i - 1])); } dp[u][i] = std::max(dp[u][i], dp[v][i]); } } } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n; std::cin >> n >> V; for (int i = 1; i <= n; i++) { std::cin >> a[i]; } for (int i = 1; i < n; i++) { int u, v; std::cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } ll answer = 0; for (int i = 1; i <= 1; i++) { for (int u = 1; u <= n; u++) { for (int v = 0; v <= V; v++) { dp[u][v] = -1e18; } } dfs(i); answer = std::max(answer, dp[i][V]); } std::cout << answer; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 4696 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 4696 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 89172 KB | Output is correct |
2 | Correct | 101 ms | 91220 KB | Output is correct |
3 | Correct | 53 ms | 87752 KB | Output is correct |
4 | Correct | 46 ms | 87376 KB | Output is correct |
5 | Correct | 89 ms | 87444 KB | Output is correct |
6 | Correct | 90 ms | 87376 KB | Output is correct |
7 | Correct | 90 ms | 87380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 4696 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |