(* O(n log n) *)
open Printf;;
Scanf.scanf " %d" @@ fun n ->
  let g = Array.make n [] in
  for _ = 1 to n - 1 do
    Scanf.scanf " %d %d" @@ fun u v ->
      let u, v = u - 1, v - 1 in
      g.(u) <- v :: g.(u);
      g.(v) <- u :: g.(v);
  done;
  let cs = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
  Array.sort (fun x y -> y - x) cs;
  let ans = Array.make n 0 in
  let rec dfs v p i =
      ans.(v) <- cs.(i);
      let f j v2 = if v2 <> p then dfs v2 v (i + 1 + j) in
      List.iteri f g.(v) in
  dfs 0 (-1) 0;
  Array.fold_left (+) 0 cs - cs.(0) |> printf "%d\n";
  printf "%d" ans.(0);
  Array.sub ans 1 @@ n - 1 |> Array.iter @@ printf " %d";
  print_newline ()