# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
468956 |
2021-08-30T09:36:42 Z |
Autumn |
Chase (CEOI17_chase) |
C++17 |
|
57 ms |
7108 KB |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
vector<vector<int>> graph;
vector<int> pigeons;
int dfs(int v, int p, int bread){
int x=0;
for(int u:graph[v]){
x+=pigeons[u];
}
if(p==-1) x+=pigeons[v];
pigeons[v]=x;
if(bread==1)return x;
int oha=0;
for(auto u:graph[v]){
if(p==u)continue;
oha = max(dfs(u,v,bread-1),oha);
}
//cout<<v<<": "<<x+oha<<endl;
return oha;
}
void pv(vector<int>&v){
for(auto u:v){
cout<<u<<" ";
}
cout<<endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,v;
cin>>n>>v;
graph.resize(n);
pigeons.resize(n);
for(int i=0;i<n;i++){
cin>>pigeons[i];
}
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
//pv(pigeons);
int sol= -pigeons[0] +dfs(0,-1,v);
//pv(pigeons);
cout<<sol<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
7108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |