import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.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
    edges <- VU.replicateM (n-1) $ do
        [a,b] <- getIntList
        return (a-1, b-1)
    let tree :: V.Vector [(Int,Int)]
        tree = V.create $ do
            t <- VM.replicate n []
            flip VU.imapM_ edges $ \i (a,b) -> do
                VM.modify t ((i,b) :) a
                VM.modify t ((i,a) :) b
            return t
    let colors :: VU.Vector Int
        colors = VU.create $ do
            color <- VUM.new (n-1)
            let dfs pv pc v = do
                    forM_ (zip (filter (/= pv) (tree V.! v)) (filter (/= pc) [1..])) $ \((i,a),c) -> do
                        VUM.write color i c
                        dfs (i,v) c a
            dfs (-1,-1) 0 0
            return color
    print $ VU.maximum colors
    VU.forM_ colors print