#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;
const ll INF = 1'000'000'000'000'000'000;
const int MX = 100001;
const int MX_K = 301;
vector<int> g[MX];
ll a[MX];
ll curr_path[MX_K], mx_path[MX_K];
bool taken[MX];
int sub[MX], centroid[MX];
ll ANS;
int k;
void sub_dfs(int u, int p = -1) {
sub[u] = 1;
for (int v : g[u]) {
if ((v == p) || taken[v]) continue;
sub_dfs(v, u);
sub[u] += sub[v];
}
}
int find_centroid(int mx_sub, int u, int p = -1) {
for (int v : g[u]) {
if ((v == p) || taken[v]) continue;
if (sub[v] > mx_sub) return find_centroid(mx_sub, v, u);
}
return u;
}
void go(int dep, ll val, int u, int p = -1) {
if (dep > k) return;
curr_path[dep] = max(curr_path[dep], val);
for (int v : g[u]) if (!taken[v]) {
if (v == p) continue;
go(dep + 1, val + a[v], v, u);
}
}
void decompose(int u, int p = -1) {
sub_dfs(u);
int root = find_centroid(sub[u]/2, u);
taken[root] = 1;
centroid[root] = (p == -1) ? root : p;
int i;
for (i = 0; i <= k; ++i) mx_path[i] = 0;
mx_path[0] = a[root];
for (int v : g[root]) if (!taken[v]) {
for (i = 0; i <= k; ++i) curr_path[i] = -INF;
curr_path[0] = a[root];
go(1, a[root] + a[v], v, root);
for (i = 0; i <= k; ++i) {
ANS = max(ANS, curr_path[i] + mx_path[k-i] - a[root]);
}
for (i = 0; i <= k; ++i) {
mx_path[i] = max(mx_path[i], curr_path[i]);
}
}
ANS = max(ANS, mx_path[k]);
for (int v : g[root]) {
if (taken[v]) continue;
decompose(v, root);
}
}
vector<int> get_dis(int n, int u) {
vector<int> dis(n, -1);
queue<int> q;
dis[u] = 0;
q.push(u);
while (!q.empty()) {
u = q.front(); q.pop();
for (int v : g[u]) {
if (dis[v] == -1) {
dis[v] = dis[u] + 1;
q.push(v);
}
}
}
return dis;
}
void init(int n) {
for (int i = 0; i <= n; ++i) {
g[i].clear();
taken[i] = 0;
}
}
int main() {
FAST;
int n, i, u, v;
cin >> n >> k;
--k;
init(n);
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 1; i < n; ++i) {
cin >> u >> v;
--u; --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> dis = get_dis(n, 0);
int x = *max_element(dis.begin(), dis.end());
for (u = 0; u < n; ++u) {
if (dis[u] == x) break;
}
dis = get_dis(n, u);
x = *max_element(dis.begin(), dis.end());
ANS = 0;
if (x >= k) decompose(0);
cout << ANS << "\n";
return 0;
}