# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46343 | RezwanArefin01 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 6 ms | 5240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e5 + 10;
vector<int> adj[maxn];
ll p[maxn], s[maxn], mx;
multiset<ll> st;
int n, v;
void solve(int u, int par) {
st.insert(s[u] - p[par]);
ll tot = 0; int tk = v;
for(auto it = --st.end(); it != st.begin() && tk; it--, tk--) {
tot += *it;
} mx = max(mx, tot);
for(int v : adj[u]) if(v - par) solve(v, u);
st.erase(st.find(s[u] - p[par]));
}
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
scanf("%d %d", &n, &v);
for(int i = 1; i <= n; i++)
scanf("%lld", &p[i]);
for(int i = 1; i < n; i++) {
int u, v;
scanf("%d %d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; i++) {
for(int v : adj[i]) s[i] += p[v];
}
if(n > 1000) solve(1, 0);
else for(int i = 1; i <= n; i++) {
st.clear();
solve(i, 0);
}
printf("%lld\n", mx);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |