| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 499921 | RambaXGorilla | Chase (CEOI17_chase) | C++17 | 339 ms | 359092 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.
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair <ll,int> lli;
int N, V;
int pigs[100010];
vector <int> adj[100010];
ll childBest, childUps[110], childDowns[110];
void topTwo(lli a[], lli b){
if(b > a[0]){
a[1] = a[0];
a[0] = b;
}
else if(b > a[1]){
a[1] = b;
}
}
void recur(int stat, int par){
lli topUps[110][2] = {}, topDowns[110][2] = {};
ll best = 0;
ll surrSum = 0;
for(int i = 0;i < adj[stat].size();i++){
surrSum += pigs[adj[stat][i]];
}
for(int i = 0;i < adj[stat].size();i++){
int next = adj[stat][i];
if(next != par){
recur(next, stat);
best = max(best, childBest);
for(int j = V;j > 0;j--){
topTwo(topUps[j], lli(max(childUps[j], childUps[j - 1] + surrSum - pigs[next]), next));
topTwo(topDowns[j], lli(childDowns[j], next));
}
}
}
topTwo(topUps[1], lli(surrSum, stat));
for(int i = 0;i < V + 1;i++){
for(int j = 0;j < 2;j++){
if(topUps[i][j].second != topDowns[V - i][0].second){
best = max(best, topUps[i][j].first + topDowns[V - i][0].first);
}
else{
best = max(best, topUps[i][j].first + topDowns[V - i][1].first);
}
}
}
childBest = best;
for(int i = V;i > 0;i--){
childUps[i] = topUps[i][0].first;
childDowns[i] = max(topDowns[i][0].first, topDowns[i - 1][0].first + surrSum - pigs[par]);
}
}
int main(){
scanf("%d%d",&N,&V);
pigs[0] = 0;
for(int i = 1;i < N + 1;i++){
scanf("%d",&pigs[i]);
}
for(int i = 0;i < N - 1;i++){
int a, b;
scanf("%d%d",&a,&b);
adj[a].push_back(b);
adj[b].push_back(a);
}
recur(1, 0);
printf("%lld",childBest);
}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... | ||||
