#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];
    for(int i=1;i<=n;i++) cin>>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);
    }
    cout<<niz[1]<<" 1 1 0";
    return 0;
}