#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


vector<vector<long long> > g;
vector<long long> a;
vector<char> used;
vector<long long> ans;

long long dfs(long long v){
  used[v] = true;
  ans[a[v]]++;
  long long c = 0;
  for(int i: g[v]){
    if(!used[i]){
      c += dfs(i);
    }
  }
  ans[a[v]] += c;
  return c + 1;
}


int main() {
  long long n;
  cin >> n;
  a.resize(n + 1);
  for(int i = 1; i <= n; ++i) cin >> a[i];
  g.resize(n + 1, vector<long long>(n + 1));
  long long fr, to;
  for(int i = 0; i < n - 1; ++i){
    cin >> fr >> to;
    g[fr].push_back(to);
    g[to].push_back(fr);
  }
  ans.resize(n + 1);
  for(int i = 1; i <= n; ++i){
    used.assign(n + 1, false);
    dfs(i);
  }
  for(int i = 1; i <= n; ++i) cout << ans[i] / 2 << endl;
}