Submission #469043

#TimeUsernameProblemLanguageResultExecution timeMemory
469043paga2004Chase (CEOI17_chase)C++17
20 / 100
4035 ms13320 KiB
#include <bits/stdc++.h> #ifdef LOCAL #define dbg(x) cerr << "dgb: " << x << "\n"; #else #define dbg(x) #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,tune=native") #endif using namespace std; #define int long long int n; vector<int> c; vector<int> sum; vector<vector<int>> g; int f(int v, int p, int k) { if (k == 0) return 0; int maxi = 0; for (int w : g[v]) { if (w == p) continue; maxi = max(maxi, f(w, v, k - 1) + sum[v] - ((p == -1) ? 0 : c[p])); maxi = max(maxi, f(w, v, k)); } return maxi; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int k; cin >> n >> k; c.resize(n); g.resize(n); sum.assign(n, 0); for (int &x : c) cin >> x; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[b].push_back(a); g[a].push_back(b); sum[a] += c[b]; sum[b] += c[a]; } if (n <= 10) { int best = 0; for (int root = 0; root < n; root++) best = max(best, f(root, -1, k)); cout << best << "\n"; } else { cout << f(0, -1, k) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...