#include <bits/stdc++.h>

using namespace std;

int n,m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,a;
    cin>>n;
    int mini=INT_MAX,id,niz[n+5],zbir=0;
    for(int i=1;i<=n;i++)
    {
        cin>>niz[i];
        zbir+=niz[i];
    }
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        if(min(min(niz[a],niz[b]),mini)==niz[a]) id=a;
        else if(min(min(niz[a],niz[b]),mini)==niz[b]) id=b;
        mini=min(min(niz[a],niz[b]),mini);
    }
    if(n==2)
    {
        if(niz[1]<niz[2]) cout<<niz[1]<<" 1 1 0";
        else cout<<niz[2]<<" 1 2 0"
    }
    else if(zbir-niz[1]>=niz[1]) cout<<niz[1]<<" 1 1 0";
    else
    {
        cout<<zbir-niz[1]<<" ";
        cout<<n-1<<" ";
        for(int i=2;i<=n;i++) cout<<i<<" ";
        cout<<0;
    }
    return 0;
}