#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N;
bool judge[400005];
ll ans[400005];
ll sum[400005];
ll A[400005];
void solve(){
    vector<P>AA(2*N);
    for(ll i=0;i<2*N;i++)AA[i]=P(A[i],i);
    sort(AA.begin(),AA.end());
    for(ll i=0;i<N;i++)judge[AA[i].second]=true;
for(ll i=1;i<=2*N;i++){
    if(judge[i-1])sum[i]=sum[i-1]+1;else sum[i]=sum[i-1]-1;
}for(ll i=1;i<=2*N;i++)sum[i]=abs(sum[i]);
string ans="";
for(ll i=1;i<=2*N;i++)
if(sum[i-1]<sum[i])ans+='(';else ans+=')';
cout<<ans<<endl;
}
int main(){
    cin>>N;
    for(ll i=0;i<2*N;i++)cin>>A[i];
solve();
}
// Problem: E - Unique Color
// Contest: AtCoder - AtCoder Beginner Contest 198
// URL: https://atcoder.jp/contests/abc198/tasks/abc198_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
using namespace std;
typedef long long ll;

int read() {
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int N=1e5+5;

vector<int> G[N],ans;

int book[N];
int c[N];
int n;

void dfs(int now,int fa) {
	if(!book[c[now]]) ans.pb(now);
	book[c[now]]++;
	for(int i=0;i<sz(G[now]);i++) {
		int to=G[now][i];
		if(to==fa) continue;
		dfs(to,now);
	}
	book[c[now]]--;
}

int main() {
	n=read();
	for(int i=1;i<=n;i++) c[i]=read();
	for(int i=1;i<=n-1;i++) {
		int x=read(),y=read();
		G[x].pb(y),G[y].pb(x);
	}
	dfs(1,0);
	sort(ans.begin(),ans.end());
	for(int i=0;i<sz(ans);i++) {
		printf("%d\n",ans[i]);
	}
	return 0;
}
