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: from operator import mul
  from functools import reduce
  
  # from collections import Counter
  # from itertools import combinations as comb
  # from itertools import permutations as perm
  # from copy import copy
  # 配列二分法アルゴリズム
  # https://docs.python.jp/3/library/bisect.html
  # import bisect
  # 桁数指定
  # print('{:.3f}'.format(X))
  # from collections import defaultdict
  # dic = defaultdict(lambda: ...)
  # 値で辞書をソート
  # sorted(dic.items(), key=lambda x:x[1])
  # ヒープキュー
  # https://docs.python.org/ja/3/library/heapq.html
  # import heapq
  # 正規表現(regular expression)のためのモジュール
  # import re
  
  import sys
  
  sys.setrecursionlimit(10**6)
  
  
  def inpl():
      return list(map(int, input().split()))
  
  
  # 重複組み合わせは nHr = (n + r - 1)Cn
  def cmb(n, r):
      # combination
      if n < r:
          return 0
      r = min(n - r, r)
      if r == 0:
          return 1
      over = reduce(mul, range(n, n - r, -1))
      under = reduce(mul, range(1, r + 1))
      return over // under
  
  
  def gcd(a, b):
      # greatest common divisor
      while b > 0:
          a, b = b, a % b
  
      return a
  
  
  def lcm(a, b):
      # least common multiple
      return a * b // gcd(a, b)
  
  
  def dfs(visit, a, v_b, v_color):
      visit[a] = True
  
      # t_list = [t for t in tmp_list[a] if t != v_b]
      # t_color = [c for c in range(ans) if v_color != c]
      # print(t_list, t_color)
      flag = True
      i = 0
      for b in tmp_list[a]:
          if b == v_b:
              continue
          # print(a, b, c)
          # color[a][c] = True
          # color[b][c] = True
          if flag is True and i >= v_color:
              flag = False
              i += 1
          c = i
          ans_c[min(a, b), max(a, b)] = c
          dfs(visit, b, a, c)
          i += 1
  
      return
  
  
  N = int(input())
  AB = [inpl() for i in range(N - 1)]
  
  ans_c = {}
  tmp_list = [[] for i in range(N + 1)]
  for a, b in AB:
      tmp_list[a].append(b)
      tmp_list[b].append(a)
  
  ans = max(len(a) for a in tmp_list)
  # print(ans, "ans")
  # color = [[False for j in range(ans)] for i in range(N + 1)]
  visit = [False for i in range(N + 1)]
  dfs(visit, 1, N + 1, ans + 1)
  
  print(ans)
  for a, b in AB:
      print(ans_c[a, b] + 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"}]