Submission #468957

#TimeUsernameProblemLanguageResultExecution timeMemory
468957AutumnChase (CEOI17_chase)C++17
0 / 100
51 ms7192 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...