output_description: Print N lines.
  
  The first line should contain K, the number of colors used.
  
  The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
  representing the color of the i-th edge, where 1 \le c_i \le K must hold.
  
  If there are multiple colorings with the minimum number of colors that satisfy
  the condition, printing any of them will be accepted.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      a_1 b_1
      a_2 b_2
      \vdots
      a_{N-1} b_{N-1}
attempt: # 920~
  # 解法 よく考えたら一度解いた問題な気がする
  #  936 まず，最も接続数が多いノードについて，異なる色を決める，
  #  他のノードについては，自分が現在接続されているものとは違う色を適当に選んでつける
  # 実装
  # ノードの色塗りの仕方がわからない. (x,y) = colorってしちゃうと，N*Nのlistを作らないとイケなくない？？
  #
  
  N = int(input())
  A = [[] for _ in range(N)]
  J = []
  col = {}
  
  
  for _ in range(N - 1):
      ai, bi = map(int, input().split())
      A[ai - 1].append(bi)
      A[bi - 1].append(ai)
      J.append([ai, bi])
  
  node_num = [len(a) for a in A]
  
  
  # 親から子へ探索をする．ノードごとにつながっているノードを取り出してきて，それが親なら無視する．親以外なら親以外の色をつけて，
  # 自身が親となってdfsを返す.
  def dfs(this_node, parent_node, parent_color):
      # 入力　今のノード,親のエッジ， 親の色，
      # エッジに色を塗る
      # 出力　子のエッジ，子の色
      # 終了条件 なし 親のノードしかないノードに行くと，勝手に探索をやめる
      this_color = 0
      for a in A[this_node - 1]:
          if a == parent_node:
              continue
          if this_color == parent_color:
              this_color += 1
          if this_node > a:
              tmp = this_node
              this_node = a
              a = tmp
          col[(this_node, a)] = this_color
          this_color += 1
          dfs(a, this_node, this_color - 1)
  
  
  # 子供がいる場合は，そいつらにつなぐ
  dfs(1, -1, -1)
  # 最終的にはエッジを選んで出力しないといけない
  print(max(node_num))
  for j in J:
      j = tuple(j)
      print(col[j] + 1)
  
problem_description: Statement
  
  Given is a tree G with N vertices. The vertices are numbered 1 through N, and
  the i-th edge connects Vertex a_i and Vertex b_i.
  
  Consider painting the edges in G with some number of colors. We want to paint
  them so that, for each vertex, the colors of the edges incident to that vertex
  are all different.
  
  Among the colorings satisfying the condition above, construct one that uses
  the minimum number of colors.
samples: [{"input": "3\n    1 2\n    2 3", "output": "2\n    1\n    2\n    \n\n* * *"}, {"input": "8\n    1 2\n    2 3\n    2 4\n    2 5\n    4 7\n    5 6\n    6 8", "output": "4\n    1\n    2\n    3\n    4\n    1\n    1\n    2\n    \n\n* * *"}, {"input": "6\n    1 2\n    1 3\n    1 4\n    1 5\n    1 6", "output": "5\n    1\n    2\n    3\n    4\n    5"}]