Under construction

Still being built. Things may change

City Attractions

Time limit2sMemory limit64 MB

Summary
On a weighted tree, Gigel repeatedly jumps from his current city to the city maximizing a_y - dist(x, y), breaking ties by smallest index, and we must report his position after K days.
Level

Hard8 of 10

Topics
Tree, DFS, Binary search, Divide and conquer
Solved
No attempts yet

Problem

Moldova has NN cities, numbered 1 through NN, and bidirectional roads join some pairs of them. To keep the budget small the government built exactly N−1N - 1 roads, and you can still travel between any two cities along them.

By national decree every city has a non-negative integer beauty. City ii has beauty aia_i. Two different cities may have equal beauty.

Gigel has arrived in Moldova and is in city 1. He wants to see many beautiful cities, but his time is short and he cannot make up his mind. He stays for KK more days and visits one city each day. On day ii he starts from the city xx he ended the previous day in (x=1x = 1 on the first day) and looks for a city yy with y≠xy \ne x that maximizes ay−d(x,y)a_y - d(x, y), where d(x,y)d(x, y) is the smallest number of roads on a route from xx to yy. If several cities reach that maximum, he takes the one with the smallest index. He travels to yy and spends the rest of day ii there. The next day he applies the same rule again.

Write a program that finds the city Gigel is in at the end of day KK.

Input

The first line contains two integers NN and KK, the number of cities and the number of days Gigel stays. The second line contains NN integers a1,a2,…,aNa_1, a_2, \dots, a_N, where aia_i is the beauty of city ii. Each of the next N−1N - 1 lines contains two integers uiu_i and viv_i, meaning that a bidirectional road joins city uiu_i and city viv_i.

Output

Print one integer, the index of the city Gigel is in at the end of day KK.

Limits

  • 2≤N≤3×1052 \le N \le 3 \times 10^5
  • 1≤K≤10181 \le K \le 10^{18}
  • 0≤ai≤1090 \le a_i \le 10^9
  • 1≤ui,vi≤N1 \le u_i, v_i \le N
  • ui≠viu_i \ne v_i
  • The N−1N - 1 roads connect all cities.

Hint

In the first example Gigel leaves city 1 for city 3 on day 1, moves from city 3 to city 5 on day 2, and moves from city 5 to city 2 on day 3. On day 4, the last day, he leaves city 2 for city 5 again.

Examples2

  1. Example 1

    Input
    5 4
    1 1 3 2 4
    1 2
    1 3
    2 4
    2 5
    
    Expected output
    5
    
  2. Example 2

    Input
    2 1
    5 7
    1 2
    
    Expected output
    2