#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 200010
#define INF 1000000000000010LL

using namespace std;

int n;
ll a[MAXN], dp[MAXN][5], d[MAXN];
bool bio[MAXN];
vector<int> g[MAXN];
vector<pii> svi;
vector<int> crni, beli;

void dfs(int u)
{
    bio[u]=true;
    ll zanula=0, zajedan=0, zadva=0;
    pair< ll, ll > zajedanmin={INF, -1};
    for (auto v:g[u])
    {
        if (!bio[v])
        {
            d[v]=d[u]+1;
            dfs(v);

            zanula+=dp[v][1];

            zajedan+=min(dp[v][1], dp[v][2]);
            zajedanmin=min(zajedanmin, {dp[v][2]-min(dp[v][1], dp[v][2]), v});

            zadva+=min(dp[v][0], min(dp[v][1], dp[v][2]));
        }
    }
    if (g[u].size()>1 || u==1)
    {
        dp[u][0]=zanula;

        int v=zajedanmin.yy;
        dp[u][1]=zajedan-min(dp[v][1], dp[v][2])+dp[v][2];

        dp[u][2]=zadva+a[u];

        if (dp[u][0]>INF) dp[u][0]=INF;
        if (dp[u][1]>INF) dp[u][1]=INF;
        if (dp[u][2]>INF) dp[u][2]=INF;
    }
    else
    {
        dp[u][0]=0;
        dp[u][1]=INF;
        dp[u][2]=a[u];
    }
    //cout<<u<<": "<<dp[u][0]<<" "<<dp[u][1]<<" "<<dp[u][2]<<endl;

}

void rekon(int u, int k)
{
    bio[u]=true;
    if (k==2)
    {
        svi.pb({u, d[u]});
        for (auto v:g[u])
        {
            if (!bio[v])
            {
                if (dp[v][0]<=dp[v][1] && dp[v][0]<=dp[v][2]) rekon(v, 0);
                else if (dp[v][1]<=dp[v][0] && dp[v][1]<=dp[v][2]) rekon(v, 1);
                else rekon(v, 2);
            }
        }
    }
    else if (k==0)
    {
        for (auto v:g[u])
            if (!bio[v])
                rekon(v, 1);
    }
    else //if (k==1)
    {
        pair<ll, ll> zajedanmin={INF, -1};
        for (auto v:g[u])
        {
            if (!bio[v]) zajedanmin=min(zajedanmin, {dp[v][2]-min(dp[v][1], dp[v][2]), v});
        }

        int koji=zajedanmin.yy;
        for (auto v:g[u])
        {
            if (!bio[v])
            {
                if (v==koji) rekon(v, 2);
                else
                {
                    if (dp[v][1]<=dp[v][2])
                        rekon(v, 1);
                    else //if (dp[v][2]<dp[v][1])
                        rekon(v, 2);
                }
            }
        }
    }
}

int main()
{
    cin>>n;
    bool isti=true;
    for (int i=1; i<=n; i++) { cin>>a[i]; if (i>1 && a[i]!=a[i-1]) isti=false; }

    ll pomoc=-1;
    if (isti) { pomoc=a[1]; for (int i=1; i<=n; i++) a[i]=1; }

    //if (n<=10) assert(0);

    for (int i=1; i<n; i++)
    {
        int u, v; cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }

    //if (g[1].size()==1) assert(0);

    d[1]=0;
    dfs(1);
    //cout<<dp[1][0]<<" "<<dp[1][1]<<" "<<dp[1][2]<<endl;

    for (int i=1; i<=n; i++)
    {
        if (d[i]%2) crni.pb(i);
        else beli.pb(i);
    }

    cout<<beli.size()<<endl;
    for (auto x:beli) cout<<x<<" ";
    cout<<endl;

    cout<<crni.size()<<endl;
    for (auto x:crni) cout<<x<<" ";

    exit(0);

    if (!isti) cout<<min(dp[1][1], dp[1][2])<<endl;
    else cout<<(ll)(min(dp[1][1], dp[1][2])*pomoc)<<endl;

    for (int i=1; i<=n; i++) bio[i]=false;
    if (dp[1][2]<=dp[1][1]) rekon(1, 2);
    else rekon(1, 1);

    //for (auto par:svi) cout<<par.xx<<" "<<par.yy<<endl;

    for (auto par:svi)
    {
        if (par.yy%2) crni.pb(par.xx);
        else beli.pb(par.xx);
    }

    cout<<beli.size()<<endl;
    for (auto x:beli) cout<<x<<" ";
    cout<<endl;

    cout<<crni.size()<<endl;
    for (auto x:crni) cout<<x<<" ";
}