# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132152 | Vardanyan | Chase (CEOI17_chase) | C++14 | 959 ms | 8632 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 <bits/stdc++.h>
using namespace std;
const int N = 100*1000+5;
int d[N];
long long ans = 0;
int qn;
vector<int> g[N];
void dfs(int v,int p = -1,int hm = qn,long long now = 0){
if(hm == 0){
ans = max(ans,now);
return;
}
for(int i = 0;i<g[v].size();i++){
int to = g[v][i];
if(to == p) continue;
now+=d[to];
}
for(int i = 0;i<g[v].size();i++){
int to = g[v][i];
if(to == p) continue;
dfs(to,v,hm-1,now);
}
}
int main(){
ios_base::sync_with_stdio(false);
int n;
cin>>n>>qn;
for(int i = 1;i<=n;i++) cin>>d[i];
for(int i = 0;i<n-1;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
for(int i = 1;i<=n;i++){
dfs(i);
}
cout<<ans<<endl;
return 0;
}
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... |