PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000382. Tối đa hóa giá trị tại gốc (Maximizing Root)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối đa hóa giá trị tại gốc (Maximizing Root)

Maximizing Root

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You have a tree of nn vertices rooted at vertex 11. Vertex ii initially has a positive value aia_i. You may perform at most kk operations:

  1. Select a vertex vv that has not been selected before.
  2. Choose a positive integer xx dividing the current values of all vertices in the subtree rooted at vv.
  3. Multiply all values in that subtree by xx.

A vertex may be selected directly at most once, but an ancestor's operation may affect it again. A subtree includes its root. Maximize the final value of vertex 11.

PHOJ input convention: Each input file contains a single tree with no leading test count tt.

Input

The first line contains n,kn,k. The second line contains the nn vertex values. The following n−1n-1 lines contain undirected edges u,vu,v forming a tree.

Output

Print the maximum achievable final value of vertex 11.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le12, 0≤k≤n0\le k\le n, 1≤ai≤601\le a_i\le60; valid tree.

  • Subtask 2 (30 points): 2≤n≤2 0002\le n\le2\,000, 0≤k≤n0\le k\le n, 1≤ai≤1 0001\le a_i\le1\,000; valid tree.

  • Subtask 3 (50 points): 2≤n≤100 0002\le n\le100\,000, 0≤k≤n0\le k\le n, 1≤ai≤1 0001\le a_i\le1\,000; valid tree.

Examples

Example 1

Input

5 2
24 12 24 6 12
1 2
1 3
2 4
2 5

Output

288

Explanation

First select vertex 44 with multiplier 22; the values become [24,12,24,12,12][24,12,24,12,12]. Now all values are multiples of 1212, so select the root with multiplier 1212, giving root value 288288. This is optimal within two operations.

Example 2

Input

5 3
24 12 24 6 12
1 2
1 3
2 4
2 5

Output

576

Explanation

Select vertex 44 with multiplier 22, then vertex 22 with multiplier 44, and finally the root with multiplier 2424. The root becomes 24⋅24=57624\cdot24=576.