Imports System.Collections.Generic
Public Class Edge
  Private _Id As Integer
  Public Property Id As Integer
    Get
      Return _Id
    End Get
    Set(value As Integer)
      _Id = value
    End Set
  End Property
  Private _ToVertexId As Integer
  Public Property ToVertexId As Integer
    Get
      Return _ToVertexId
    End Get
    Set(value As Integer)
      _ToVertexId = value
    End Set
  End Property
  Public Sub New(toVertexId As Integer, id As Integer)
    Me.Id = id
    Me.ToVertexId = toVertexId
  End Sub
End Class

Public Class Program
  Shared Ans As Integer()
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    ReDim Ans(0 To n - 2)
    Dim graph As Dictionary(Of Integer, List(Of Edge)) = New Dictionary(Of Integer, List(Of Edge))()
    For i As Integer = 0 To n - 2
      Dim ab As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
      If Not graph.ContainsKey(ab(0)) Then graph(ab(0)) = New List(Of Edge)()
      If Not graph.ContainsKey(ab(1)) Then graph(ab(1)) = New List(Of Edge)()
      graph(ab(0)).Add(New Edge(ab(1), i))
      graph(ab(1)).Add(New Edge(ab(0), i))
    Next
    Dfs(1, graph)
    Dim maxAns As Integer = 0
    For Each i As Integer In Ans
      maxAns = Math.Max(maxAns, i)
    Next
    Console.WriteLine(maxAns.ToString())
    For i As Integer = 0 To Ans.Length - 1
      Console.WriteLine(Ans(i).ToString())
    Next
  End Sub
  
  Shared Sub Dfs(current As Integer, graph As Dictionary(Of Integer, List(Of Edge)), Optional parent As Integer = -1, Optional color As Integer = -1)
    Dim k As Integer = 1
    For Each nodes As Edge In graph(current)
      Dim toVertexId As Integer = nodes.ToVertexId
      Dim id As Integer = nodes.Id
      If Not toVertexId = parent Then
        If k = color Then k += 1
        Ans(id) = k
        k += 1
        Dfs(toVertexId, graph, current, Ans(id))
      End If
    Next
  End Sub
End Class