#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<vector<bool>> stablo(n, vector<bool>(n, false));
    vector<int> cvorovi(n);

    for (int i = 0; i < n; i++)
    {
        cin >> cvorovi[i];
    }

    for (int i = 0, c1, c2; i < n - 1; i++)
    {
        cin >> c1 >> c2;
        stablo[c1][c2] = true;
        stablo[c2][c1] = true;
    }

    bool cvor1_povezan_sa_svima = true;

    for (int i = 1; i < n; i++)
    {
        if (!stablo[0][i])
        {
            cvor1_povezan_sa_svima = false;
            break;
        }
    }

    if (cvor1_povezan_sa_svima)
    {
        std::cout << cvorovi[0] << "\n1\n1\n0";
    }
    
    return 0;
}