local n = io.read("*n")
local nodecol = {}
local edgecol = {}
local edge = {}
for i = 1, n do
  nodecol[i] = 0
  edge[i] = {}
end
for i = 1, n - 1 do
  edgecol[i] = 0
  local a, b = io.read("*n", "*n")
  edge[a][b] = i
  edge[b][a] = i
end
local snode = 0
for i = 1, n do
  local edgecnt = 0
  for k, v in pairs(edge[i]) do
    edgecnt = edgecnt + 1
  end
  if edgecnt == 1 then
    snode = i
    break
  end
end
nodecol[snode] = 1
local tasknode = {}
for dstnode, edgeid in pairs(edge[snode]) do
  nodecol[dstnode] = 1
  edgecol[edgeid] = 1
  table.insert(tasknode, dstnode)
end
local maxcol = 1
local mma = math.max
for i = 1, n - 1 do
  local srcnode = tasknode[i]
  local srccol = nodecol[srcnode]
  local curcol = 1
  for dstnode, edgeid in pairs(edge[srcnode]) do
    if nodecol[dstnode] == 0 then
      if curcol == srccol then curcol = curcol + 1 end
      nodecol[dstnode] = curcol
      edgecol[edgeid] = curcol
      maxcol = mma(maxcol, curcol)
      table.insert(tasknode, dstnode)
      curcol = curcol + 1
    end
  end
end
print(maxcol)
for i = 1, n - 1 do
  print(edgecol[i])
end
