import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.List
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM


readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  vs <- replicateM (n-1) getIntList
  cs <- getIntList

  ws <- VM.new (n+1)
  VM.set ws (0::Int)

  forM_ vs $ \[a, b] -> do
    wa <- VM.read ws a
    VM.write ws a (wa+1)
    wb <- VM.read ws b
    VM.write ws b (wb+1)

  wdict <- forM [1..n] $ \i -> do
    w <- VM.read ws i
    return (w, i)

  let wdict' = sort wdict

  nodes <- VM.new (n+1)
  forM_ (zip cs wdict) $ \(d, (_, i)) -> VM.write nodes (i-1) d
  nodes' <- V.freeze nodes

  print . sum $  fmap (\[a, b] -> min (nodes' V.! (a-1)) (nodes' V.! (b-1))) vs

  forM_ [1..n] $ \i -> do
    when (i > 1) $ putStr " "
    putStr . show $ nodes' V.! (i-1)

  putStrLn ""