Submission #469036

# Submission time Handle Problem Language Result Execution time Memory
469036 2021-08-30T13:19:52 Z paga2004 Chase (CEOI17_chase) C++17
0 / 100
4000 ms 12788 KB
#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;

int n;
vector<int> c;
vector<int> sum;
vector<vector<int>> g;

int f(int v, int p, int k, bool dropped) {
  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, true) + sum[v] - (dropped ? 0 : c[v]));
    maxi = max(maxi, f(w, v, k, false));
  }
  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.resize(n);
  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];
  }

  int best = 0;
  for (int root = 0; root < n; root++)
    best = max(best, f(root, root, k, false));

  cout << best << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 12788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -