# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
469039 |
2021-08-30T13:25:15 Z |
paga2004 |
Chase (CEOI17_chase) |
C++17 |
|
4000 ms |
12800 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) {
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.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, -1, k));
cout << best << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4066 ms |
12800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |