n = gets.to_i
g = n.times.map{[]}
ab = (n-1).times.map{
  a,b = gets.split.map(&:to_i)
  g[a-1]<<b-1
  g[b-1]<<a-1
  [a,b]
}

q = [0]
used = [nil]*n
used[0] = true
ar = [0]*n
k = g.map{|gg|gg.size}.max
ans = n.times.map{[0]*n}
cnt = 0
while q.size!=0
  now = q.shift
  g[now].each.with_index{|v,i|
    if !used[v]
      ans[now][v] = cnt%k+1
      ans[v][now] = cnt%k+1
      used[v] = true
      q << v
      cnt += 1
    end
  }
end

p k
ab.each{|(a,b)|
  p ans[a-1][b-1]
}