output_description: Print the answers for k = 1, 2, ..., N in order, each in its own line.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      c_1 c_2 ... c_N
      a_1 b_1
      :
      a_{N-1} b_{N-1}
attempt: def s0():
      return input()
  
  
  def s1():
      return input().split()
  
  
  def s2(n):
      return [input() for x in range(n)]
  
  
  def s3(n):
      return [[input().split()] for _ in range(n)]
  
  
  def n0():
      return int(input())
  
  
  def n1():
      return [int(x) for x in input().split()]
  
  
  def n2(n):
      return [int(input()) for _ in range(n)]
  
  
  def n3(n):
      return [[int(x) for x in input().split()] for _ in range(n)]
  
  
  n = n0()
  c = n1()
  ab = [(x[0], x[1]) for x in n3(n - 1)]
  
  import networkx as nx
  
  G = nx.Graph()
  
  G.add_nodes_from(range(1, n + 1))
  G.add_edges_from(ab)
  
  dict_color = {i: 0 for i in range(1, n + 1)}
  for j in c:
      dict_color[j] += 1
  
  for i in range(1, n + 1):
      for line in list(
          nx.all_simple_paths(G, source=i, target=[x for x in range(i + 1, n + 1)])
      ):
          path_color = [c[x - 1] for x in line]
          for i in set(path_color):
              dict_color[i] += 1
  
  for i in dict_color:
      print(dict_color[i])
  
problem_description: Statement
  
  We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
  connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
  and the color of Vertex i is c_i. Here, the color of each vertex is
  represented by an integer between 1 and N (inclusive). The same integer
  corresponds to the same color; different integers correspond to different
  colors.
  
  For each k=1, 2, ..., N, solve the following problem:
  
    * Find the number of simple paths that visit a vertex painted in the color k one or more times.
  
  **Note:** The simple paths from Vertex u to v and from v to u are not
  distinguished.
samples: [{"input": "3\n    1 2 1\n    1 2\n    2 3", "output": "5\n    4\n    0\n    \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times:  \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times:  \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n    1", "output": "1\n    \n\n* * *"}, {"input": "2\n    1 2\n    1 2", "output": "2\n    2\n    \n\n* * *"}, {"input": "5\n    1 2 3 4 5\n    1 2\n    2 3\n    3 4\n    3 5", "output": "5\n    8\n    10\n    5\n    5\n    \n\n* * *"}, {"input": "8\n    2 7 2 5 4 1 7 5\n    3 1\n    1 2\n    2 7\n    4 5\n    5 6\n    6 8\n    7 8", "output": "18\n    15\n    0\n    14\n    23\n    0\n    23\n    0"}]