import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import Data.Tuple (swap)

main :: IO ()
main = do
  let
    fromListN :: Int -> [(Int, Int)] -> VU.Vector Int
    fromListN n = VU.accum (flip const) (VU.replicate n 0)
    children :: Tree -> [(Int, Tree)]
    children (Node _ ts) = ts
    fromEdgesToAdjacencyVectorN :: Int -> [(Int, (Int, Int))] -> V.Vector [(Int, Int)]
    fromEdgesToAdjacencyVectorN n = V.accum (flip (:)) (V.replicate n [])
    fromAdjacencyVectorToTree :: V.Vector [(Int, Int)] -> Int -> Tree
    fromAdjacencyVectorToTree adjacency root = Node root (map (fmap (f root)) (adjacency V.! root))
      where
        f :: Int -> Int -> Tree
        f p i = Node i (map (fmap (f i)) . filter ((/= p) . snd) $ adjacency V.! i)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  abs <- map (unsafeListToPair . map (pred . unsafeTextToInt) . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  let
    adjacency = fromEdgesToAdjacencyVectorN n . concatMap (uncurry (map . fmap . (,)) . fmap ((:) <$> id <*> pure . swap)) . zip [0 ..] $ abs :: V.Vector [(Int, Int)]
    root = V.maxIndex . V.map length $ adjacency :: Int
    k = length $ adjacency V.! root :: Int
    tree = fromAdjacencyVectorToTree adjacency root :: Tree
    queue = zip (children tree) [0 ..] ++ walk k queue :: [((Int, Tree), Int)]
      where
        walk :: Int -> [((Int, Tree), Int)] -> [((Int, Tree), Int)]
        walk 0 _ = []
        walk l (((_, t), c) : rest) = zip ts [(c + 1) ..] ++ walk (l - 1 + length ts) rest
          where
            ts = children t :: [(Int, Tree)]
  print k
  VU.mapM_ (print . succ . (`mod` k)) . fromListN (n - 1) . map ((,) <$> fst . fst <*> snd) $ queue

data Tree = Node Int [(Int, Tree)]

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair = (,) <$> head <*> head . tail
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
