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 collections import defaultdict
  import random
  
  
  class Graph:
      def __init__(self):
          self.edges = defaultdict(list)
          self.weights = {}
  
      def add_edge(self, from_node, to_node, weight):
          # Note: assumes edges are bi-directional
          self.edges[from_node].append(to_node)
          self.edges[to_node].append(from_node)
          self.weights[(from_node, to_node)] = weight
          self.weights[(to_node, from_node)] = weight
  
      def edge_num(self, node):
          return len(self.edges[node])
  
      def set_weight(self, from_node, to_node, weight):
          self.weights[(from_node, to_node)] = weight
          self.weights[(to_node, from_node)] = weight
  
      def has_node_weight(self, node):
          node_set = set()
          for x in self.edges[node]:
              node_set.add(self.weights[(node, x)])
          return node_set
  
      def done(self):
          if min(self.weights) > 0:
              return True
          else:
              return False
  
  
  N = int(input())
  A = [0] * N
  B = [0] * N
  
  g = Graph()
  
  for i in range(N - 1):
      A[i], B[i] = map(int, input().split())
      A[i], B[i] = A[i] - 1, B[i] - 1
      g.add_edge(A[i], B[i], 0)
  
  lines = [0] * N
  for n in range(N):
      lines[n] = g.edge_num(n)
  
  K = max(lines)
  K_node = lines.index(K)
  
  n = 1
  for node in g.edges[K_node]:
      g.set_weight(K_node, node, n)
      n += 1
  
  for node in g.edges[K_node]:
      m = 1
      for x in g.edges[node]:
          if x == K_node:
              continue
          if m == g.weights[(node, K_node)]:
              m += 1
          g.set_weight(node, x, m)
          m += 1
  
  for n in range(N):
      for node in g.edges[n]:
          if g.weights[(n, node)] != 0:
              continue
          else:
              weight = random.choice(list(set(range(1, K + 1)) - g.has_node_weight(node)))
              g.set_weight(n, node, weight)
  
  
  def output():
      print(K)
      for i in range(N - 1):
          print(g.weights[(A[i], B[i])])
  
  
  output()
  
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"}]