# Preorder Test

For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent a i minutes building the i-th ball in the tree.

Jacob’s teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to search his whole tree to determine this; Jacob knows that she will examine the first k nodes in a DFS-order traversal of the tree. She will then assign Jacob a grade equal to the minimum a i she finds among those k nodes.

Though Jacob does not have enough time to rebuild his model, he can choose the root node that his teacher starts from. Furthermore, he can rearrange the list of neighbors of each node in any order he likes. Help Jacob find the best grade he can get on this assignment.

A DFS-order traversal is an ordering of the nodes of a rooted tree, built by a recursive DFS-procedure initially called on the root of the tree. When called on a given node v, the procedure does the following:

1. Print v.
2. Traverse the list of neighbors of the node v in order and iteratively call DFS-procedure on each one. Do not call DFS-procedure on node u if you came to node v directly from u.

Input

The first line of the input contains two positive integers, n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ n) — the number of balls in Jacob’s tree and the number of balls the teacher will inspect.

The second line contains n integers, a i (1 ≤ a i ≤ 1 000 000), the time Jacob used to build the i-th ball.

Each of the next n - 1 lines contains two integers u iv i (1 ≤ u i, v i ≤ nu i ≠ v i) representing a connection in Jacob’s tree between balls u i and v i.

Output

Print a single integer — the maximum grade Jacob can get by picking the right root of the tree and rearranging the list of neighbors.

Examples

input

5 33 6 1 4 21 22 42 51 3

output

3

input

4 21 5 5 51 21 31 4

output

1

Note

In the first sample, Jacob can root the tree at node 2 and order 2’s neighbors in the order 4, 1, 5 (all other nodes have at most two neighbors). The resulting preorder traversal is 2, 4, 1, 3, 5, and the minimum a i of the first 3 nodes is 3.

In the second sample, it is clear that any preorder traversal will contain node 1 as either its first or second node, so Jacob cannot do better than a grade of 1.

Solution:

#include <bits/stdc++.h>

using namespace std;

struct DP {
int sum;
int mx;
};

inline DP join(DP &a, DP &b) {
DP c;
c.sum = a.sum + b.sum;
c.mx = max(a.mx, b.mx);
return c;
}

const int N = 200010;

vector <int> g[N];
int total[N];
int f[N], dp[N];
bool good[N];
int a[N];
int n;

void dfs(int v, int pr) {
int sz = g[v].size();
total[v] = 1;
int sum = 0, mx = 0;
for (int j = 0; j < sz; j++) {
int u = g[v][j];
if (u == pr) {
continue;
}
dfs(u, v);
total[v] += total[u];
if (f[u] == total[u]) {
sum += f[u];
} else {
mx = max(mx, f[u]);
}
}
f[v] = sum + mx + 1;
if (!good[v]) {
f[v] = 0;
}
}

void solve(int v, int pr, int up) {
int sz = g[v].size();
vector <int> children;
for (int j = 0; j < sz; j++) {
int u = g[v][j];
if (u == pr) {
continue;
}
children.push_back(u);
}
int cnt = children.size();
int sum = 0, mx = 0;
for (int j = 0; j < cnt; j++) {
int u = children[j];
if (f[u] == total[u]) {
sum += f[u];
} else {
mx = max(mx, f[u]);
}
}
if (up == n - total[v]) {
sum += up;
} else {
mx = max(mx, up);
}
dp[v] = sum + mx + 1;
if (!good[v]) {
dp[v] = 0;
}
if (cnt == 0) {
return;
}
vector <DP> pref(cnt + 1);
vector <DP> suf(cnt + 1);
pref[0] = {0, 0};
for (int j = 0; j < cnt; j++) {
int u = children[j];
pref[j + 1] = pref[j];
if (f[u] == total[u]) {
pref[j + 1].sum += f[u];
} else {
pref[j + 1].mx = max(pref[j + 1].mx, f[u]);
}
}
suf[cnt] = {0, 0};
for (int j = cnt - 1; j >= 0; j--) {
int u = children[j];
suf[j] = suf[j + 1];
if (f[u] == total[u]) {
suf[j].sum += f[u];
} else {
suf[j].mx = max(suf[j].mx, f[u]);
}
}
for (int j = 0; j < cnt; j++) {
int u = children[j];
DP z = join(pref[j], suf[j + 1]);
if (up == n - total[v]) {
z.sum += up;
} else {
z.mx = max(z.mx, up);
}
int new_up = z.sum + z.mx + 1;
if (!good[v]) {
new_up = 0;
}
solve(u, v, new_up);
}
}

int main() {
int k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
for (int i = 0; i < n; i++) {
g[i].clear();
}
for (int i = 0; i < n - 1; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
int low = 0, high = 1000010;
while (low < high) {
int mid = (low + high + 1) >> 1;
for (int j = 0; j < n; j++) {
good[j] = (a[j] >= mid);
}
dfs(0, -1);
solve(0, -1, 0);
int best = 0;
for (int j = 0; j < n; j++) {
best = max(best, dp[j]);
}
if (best >= k) {
low = mid;
} else {
high = mid - 1;
}
}
printf("%d\n", low);
return 0;
}