#include <bits/stdc++.h>
#include <variant>

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

//using namespace harudake;

void dfs(const vector<vi32>& g, const vi32& clr, vi32& cnt, vi32& ans, i32 i, i32 p = -1) {
  if (cnt[clr[i]] == 0) ans.push_back(i+1);
  ++cnt[clr[i]];
  for (auto&& to : g[i]) {
    if (to == p) continue;
    dfs(g, clr, cnt, ans, to, i);
  }
  --cnt[clr[i]];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i32 n;
  cin>>n;
  vi32 clr(n);
  rep(i,n) cin>>clr[i];
  vector<vi32> g(n);
  rep(i,n-1) {
    i32 a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vi32 cnt(100001, 0);
  vi32 ans;
  dfs(g, clr, cnt, ans, 0);
  sort(all(ans));
  for (auto&& idx : ans) {
    cout<<idx<<"\n";
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define POW2(X) (1<<(X))
#define CKBIT(S,X) (((S)&POW2(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){ a=min(a,b); }
template<class T> inline void ckmax(T &a,T b){ a=max(a,b); }
template<class T> inline T sqr(T x){ return x*x; }
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()
template<class T> int CMP(T a[],const T b[],int n) { return memcmp(a,b,n*sizeof(T)); }
template<class T> void COPY(T a[],const T b[],int n) { memcpy(a,b,n*sizeof(T)); }
template<class T> void SET(T a[],int val,int n) { memset(a,val,n*sizeof(T)); }
using uint=unsigned int;
using int64=long long;
using uint64=unsigned long long;
using ipair=pair<int,int>;
using VI=vector<int>;
using VD=vector<double>;

int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}

int n;
unordered_map<int,int>  dp;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cin >> n;
    int minN = 1000000005,tmp;
    for(int i=0;i<n;++i){
        cin >> tmp;
        minN = min(minN, tmp);
        for(int i=1;i*i<=tmp;++i){
            if(tmp%i==0){
                if(dp[i]==0)dp[i] = tmp;
                else dp[i] = gcd(dp[i],tmp);
                int g = tmp/i;
                if(dp[g]==0)dp[g] = tmp;
                else dp[g] = gcd(dp[g],tmp);
            }
        }
    }

    int res = 0;
    dp[minN] = minN;
    for(auto bb = dp.begin();bb!=dp.end();++bb){
        if(bb->first<=minN&&bb->first == bb->second) ++res;
    }
    cout << res << endl;
    return 0;
}