#include <bits/stdc++.h>
#define endl '\n'
#define int long long

using namespace std;

bool zvezda(vector<vector<int>>&graf){
    bool rez=false;int n=graf.size()-1;
    for(int i=1; i<=n; i++){
        if(graf[i].size()==n-1)
            rez=true;
    }
    return rez;
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int n;
    cin >> n;
    vector<int> niz(n);
    for(auto&x:niz)
        cin >> x;
    vector<vector<int>> graf(n+1,vector<int>(0));
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        graf[a].push_back(b);
        graf[b].push_back(a);
    }
    if(zvezda(graf)){
        cout << 0 << endl;
        cout << 0 << endl << endl << 0;
        return 0;
    }

    return 0;
}