n = gets.to_i

edges = []
g = Array.new(n){[]}

(n-1).times do |i|
    
    e = gets.split.map(&:to_i).map{|k|k-=1}
    e[1], e[0] = e[0], e[1] if e[0] > e[1]
    g[e[0]] << e[1]
    g[e[1]] << e[1]
    edges << e
end

colors = Hash.new()
colors_used = Array.new(n){Hash.new}
used = Array.new(n){false}
# p colors
que = [0]

k = 0
while !que.empty? do
    v = que[0]
    que.shift
    # p ?a
    cur = 1
    # k = g[v].size if k < g[v].size 
    g[v].each do |w|
        k = g[v].size if k < g[v].size 
        v<w ? (i,j = v,w) : (i,j = w,v)
        next if colors[[i,j]] != nil
        # p ?b
        while colors_used[v][cur] == true do
            cur+=1
        end
        colors_used[v][cur] = true
        # colors_used[w][cur] = true
        colors[[i,j]] = cur
        que.push(w) if used[w] == false
        used[v] = true
    end
end

p k
edges.each do |e|
    p colors[e]
end






