#include <bits/stdc++.h>

using namespace std;

// Edge a bit
void Edging(vector<int> adj[], int s, int d) {
    adj[s].push_back(d);
    adj[d].push_back(s);
}

void bfs(vector<int> adj[],vector<int>& endofdabranch,vector<bool>& visited,int& vrednost,int n,vector<long long>& values)
{
    queue<int> q;
    for(int i=0;i<n;i++)//stavljam sve krajnje cvorove u queue
    {
        if(endofdabranch[i]==1){
            q.push(i);
        }
    }
    long long pom1,pomuk,najm;
    while (!q.empty()) {
        int currentNode = q.front();
        q.pop();
        bool nekob=false,imakomse=true;
        visited[currentNode]=true;
        pomuk=0;
        // doso sam do komse
        for (auto x : adj[currentNode]) {
            if(visited[x]==false){
            imakomse=false;
            pom1=-values[x];
            visited[x]=true;
            if(values[x]>0){
                pom1=values[x];
                for(auto y : adj[x]){
                    if(visited[y]==false){
                        najm=values[y];
                        for(auto z : adj[y]){
                            if(values[z]<=najm)
                                najm=values[z];
                        }
                        if(najm<0){
                            najm==0;
                        }
                        pomuk+=najm;
                    }
                    endofdabranch[y]--;
                    if(endofdabranch[y]==1){
                        q.push(y);
                    }
                }
                if(pom1<=pomuk   ){
                    values[x]=-values[x];
                    vrednost+=values[x];
                }
                else{
                    if(values[x]<=values[currentNode]){
                        values[x]=-values[x];
                        vrednost+=values[x];
                    }
                    else{
                        values[currentNode]=-values[currentNode];
                        vrednost+=values[currentNode];
                    }
                }

            }
            }
            else{
                if(values[x]<0)
                    nekob=true;
            }
        }
        if(!nekob && imakomse){
            values[currentNode]=-values[currentNode];
            vrednost+=values[currentNode];
        }

    }
}

void stampaC(vector<int> adj[], int startNode,vector<bool>& visited,vector<long long>& values)
{
    queue<int> q;
    visited[startNode] = true;
    q.push(startNode);
    int br=1,pic=1;
    while (!q.empty()) {
        int currentNode = q.front();
        q.pop();
        br--;
        for (auto neighbor : adj[currentNode]) {
            if (!visited[neighbor]) {
                visited[neighbor] = true;
                q.push(neighbor);
                if(values[neighbor]<0 && pic==-1){
                    values[neighbor]=0;
                }
            }
        }
        if(br==0){
            pic=pic*(-1);
            br=q.size();
        }
    }
}

int main() {
    int n,a,b,vred;
    vector<long long> values(220000,0);
    vector<bool> visited(220000,false);
    cin >> n;
    vector<int> endofdabranch(n,0);
    for(int i=0;i<n;i++)// values part
    {
        cin >> a;
        values[i]=a;
    }
    vector<int> adj[n];
    for(int i=0;i<n-1;i++){//edging part
        cin >> a >> b;
        a--;b--;
        Edging(adj,a,b);
        endofdabranch[a]++;
        endofdabranch[b]++;
    }
    bfs(adj,endofdabranch,visited,vred,n,values);
    cout << -vred << endl;
    visited = vector<bool>(220000,false);
    stampaC(adj,0,visited,values);
    int brC=0,brP=0;
    for(int i=0;i<n;i++){
        if(values[i]<0){
            brP++;
        }
        else if(values[i]==0){
            brC++;
        }
    }
    cout << brP << endl;
    for(int i=0;i<n;i++){
        if(values[i]<0){
            cout << i+1 << " ";
        }
    }
    if(brP!=0)
        cout << endl;
    cout << brC << endl;
    for(int i=0;i<n;i++){
        if(values[i]==0){
            cout << i+1 << " ";
        }
    }
    if(brC!=0)
        cout << endl;
    return 0;
}