output_description: Print the expected number of games that will be played, in the manner
  specified in the statement.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N A B C
attempt: import sys
  
  sys.setrecursionlimit(110000)
  
  
  def inpl():
      return list(map(int, input().split()))
  
  
  class UnionFind:
      def __init__(self, N):
          # par = parent
          self.par = [i for i in range(N)]
          self.N = N
          self.hop = {i: -1 for i in range(N)}
          self.adj = [[] for i in range(N)]
          return
  
      def root(self, x):
          if self.par[x] == x:
              return x
          else:
              self.par[x] = self.root(self.par[x])
              return self.par[x]
  
      def same(self, x, y):
          return self.root(x) == self.root(y)
  
      def union(self, x, y):
          x = self.root(x)
          y = self.root(y)
          if x == y:
              return False
  
          self.par[x] = min(x, y)
          self.par[y] = min(x, y)
          return True
  
      def find_root(self):
          for i in range(self.N):
              if i == self.root(i):
                  return i
          return
  
      def dfs(self, i):
          for nh in self.adj[i]:
              if self.hop[nh] != -1:
                  continue
              else:
                  self.hop[nh] = self.hop[i] + 1
                  self.dfs(nh)
          return
  
  
  N = int(input())
  uf = UnionFind(N)
  AB = [[0, 0] for i in range(N - 1)]
  
  for i in range(N - 1):
      a, b = inpl()
      a -= 1
      b -= 1
      AB[i][0] = a
      AB[i][1] = b
      uf.adj[a].append(b)
      uf.adj[b].append(a)
  
  C = inpl()
  
  for a, b in AB:
      uf.union(a, b)
  
  root_num = uf.find_root()
  uf.hop[root_num] = 0
  uf.dfs(root_num)
  
  dic2 = sorted(uf.hop.items(), key=lambda x: x[1], reverse=True)
  
  ans = [0 for i in range(N)]
  for i, k in enumerate(dic2):
      ans[k[0]] = i
  
  C.sort()
  
  print(sum(C[:-1]))
  for i in range(N):
      if i != 0:
          print(" ", end="")
      print(C[ans[i]], end="")
  print("")
  
problem_description: Statement
  
  Takahashi and Aoki will play a game. They will repeatedly play it until one of
  them have N wins in total.
  
  When they play the game once, Takahashi wins with probability A %, Aoki wins
  with probability B %, and the game ends in a draw (that is, nobody wins) with
  probability C %. Find the expected number of games that will be played, and
  print it as follows.
  
  We can represent the expected value as P/Q with coprime integers P and Q.
  Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q
  \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the
  constraints of this problem.)
samples: [{"input": "1 25 25 50", "output": "2\n    \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n    \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n    \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]