#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=1e3;
bool check[Max_n+3][Max_n+3];
int a[Max_n+3];
int dem[Max_n+3];
ll dp[Max_n+3];
int c[Max_n+3];
ll res = -1e18;
const ll INF = -1e13;
int n ;
ll ans_dem ;
int vi_tri ;
int trace[Max_n+3];
inline void visit ( int node ){
dp[node]= c[node] ;
dem[node]++;
for (int node_2 = 1 ; node_2 <= n ; node_2 ++ ){
if (check[node][node_2]){
check[node_2][node] = 0 ;
visit(node_2) ;
dp[node] += max ( 0ll , dp[node_2]) ;
//dp[node] = max ( 0ll , dp[node]) ;
if (dp[node_2]>0 ) dem[node]+=dem[node_2],trace[node_2] = dem[node_2] ;
}
}
//dp[u] += dp[node_2] ;
dp[node] = max(0ll,dp[node]) ;
if ( res < dp[node] ){
res = dp[node] ;
vi_tri = node ;
ans_dem = dem[node] ;
}
}
void TRY_VET ( int u , int P ){
for (int i = 1 ; i <= n ; i ++ ){
if (check[u][i] && trace[i] != 0 ){
TRY_VET( i , trace[i] ) ;
//P-=trace[i];
}
}
cout << u << ' ';
}
void solve(){
cin >> n ;
for (int i = 1 ; i <= n ; i ++ ) cin >> c[i] ;
for (int i = 1 ; i < n ; i ++ ){
int u , v; cin >> u >> v;
check[u][v] = true ;
check[v][u] = true ;
}
visit(1) ;
cout << res << ' ' << (res!=0?ans_dem:0) << '\n';
if (res!=0) TRY_VET(vi_tri , ans_dem) ;
}
_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 elaps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