#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
7192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |