[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let ABS = List.init (N - 1) (fun _ -> reads int)

    let graph =
        let g = Array.init (N + 1) (fun _ -> [])
        List.iter (fun [a;b] ->
            g.[a] <- b :: g.[a]
        ) ABS
        g

    // eprintfn "*%A" graph

    let rec s1 x =
        let fromx = graph.[x]
        let len = List.length fromx
        if len = 0 then
            0
        else
            let ns = List.map s1 fromx
            max len (List.max ns + 1)

    let color = s1 1

    // eprintfn "*%i" color

    // let edges = List.mapi (fun i [a;b] -> (i + 1, a, b)) ABS
    let mutable out = []

    let rec s2 ng x =
        let fromx = graph.[x] |> List.sort
        let mutable c = 1
        for t in fromx do
            if c = ng then c <- c + 1
            out <- (x, t, c) :: out
            s2 c t
            c <- c + 1

    s2 -1 1
    out <- List.sort out

    printfn "%i" color
    for (_, _, i) in out do
        printfn "%i" i

    0