#include <bits/stdc++.h>
#define _nhatminh int main()
#define ll long long
#define str string
#define fir first
#define sec second
#define ld long double
#define pb push_back
#define MOD 100000009
#define freopen(name) if(fopen(name".INP","r")) {freopen (name".INP","r",stdin); freopen (name".OUT","w",stdout);}
#define ALL(x) (x).begin(),(x).end()
#define piint pair < int , int >
#define piL pair < int , ll>
#define pLL pair < ll , ll >
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
using namespace std;
const int Max_n=200;
bool a[Max_n+3][Max_n+3];
ll d[Max_n+3][Max_n+3];
int c[Max_n+3];
int trace[Max_n+3][Max_n+3];
int n , p ;
const int INF = -1e9 ;
void visit ( int node ){
d[node][1] = c[node];
d[node][0] = 0 ;
for (int node_2 = 1 ; node_2 <= n ; node_2 ++ ){
if (a[node][node_2]){
a[node_2][node] = 0 ;
visit(node_2) ;
for (int i = p ; i >= 1 ; i -- )
for (int j = 1 ; j < i ; j ++){
// i - j + j = i
if (d[node][i] < (d[node][j] + d[node_2][i-j])){
d[node][i] = d[node][j] + d[node_2][i-j] ;
trace[node_2][i] = i - j ;
}
}
}
}
}
int TIM_MAX(){
ll res = 1 , ans = d[1][p];
for (int i = 2 ; i <= n ; i ++ ){
if (d[i][p] > ans ){
ans = d[i][p];
res = i ;
}
}
return res ;
}
void ANS (int node , int P ){
for (int node_2 = n ; node_2 >= 1 ; node_2 -- ){
if ( a[node][node_2] && trace[node_2][P]>0) {
ANS(node_2,trace[node_2][P]),P-=trace[node_2][P];
//cout << P << '\n';
}
}
cout << node << ' ' ;
}
void solve(){
cin >> n >> p ;
for (int i = 1 ; i <= n ; i ++ ) cin >> c[i] ;
for (int i = 2 ; i <= n ; i ++ ){
int u , v; cin >> u >> v;
a[u][v] = 1 ;
a[v][u] = 1 ;
}
memset(d , INF , sizeof(d));
visit(1);
int t = TIM_MAX();
ANS(t,p);
//cout << t << ' ' << d[t][p] << '\n';
}
_nhatminh{
freopen("");
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int q=1;
// cin >> q;
while (q--)
solve();
cerr << '\n' << "Time elapsed " << TIME << "s.\n";
return (0);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgX25oYXRtaW5oICBpbnQgbWFpbigpCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgc3RyIHN0cmluZwojZGVmaW5lIGZpciBmaXJzdAojZGVmaW5lIHNlYyBzZWNvbmQKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIE1PRCAxMDAwMDAwMDkKI2RlZmluZSBmcmVvcGVuKG5hbWUpIGlmKGZvcGVuKG5hbWUiLklOUCIsInIiKSkge2ZyZW9wZW4gKG5hbWUiLklOUCIsInIiLHN0ZGluKTsgZnJlb3BlbiAobmFtZSIuT1VUIiwidyIsc3Rkb3V0KTt9CiNkZWZpbmUgQUxMKHgpICh4KS5iZWdpbigpLCh4KS5lbmQoKQojZGVmaW5lIHBpaW50IHBhaXIgPCBpbnQgLCBpbnQgPgojZGVmaW5lIHBpTCBwYWlyIDwgaW50ICwgbGw+CiNkZWZpbmUgcExMIHBhaXIgPCBsbCAsIGxsID4KI2RlZmluZSBUSU1FICgxLjAqY2xvY2soKS9DTE9DS1NfUEVSX1NFQykKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE1heF9uPTIwMDsKYm9vbCBhW01heF9uKzNdW01heF9uKzNdOwpsbCBkW01heF9uKzNdW01heF9uKzNdOwppbnQgY1tNYXhfbiszXTsKaW50IHRyYWNlW01heF9uKzNdW01heF9uKzNdOwppbnQgbiAsIHAgOyAKY29uc3QgaW50IElORiA9IC0xZTkgOwp2b2lkIHZpc2l0ICggaW50IG5vZGUgKXsKCWRbbm9kZV1bMV0gPSBjW25vZGVdOwoJZFtub2RlXVswXSA9IDAgOwoJZm9yIChpbnQgbm9kZV8yID0gMSA7IG5vZGVfMiA8PSBuIDsgbm9kZV8yICsrICl7CgkJaW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