'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  let tree = [...new Array(N+1)].map(a => [])
  let colors = 1
  let ans = []

  inp.forEach(r => {
    r = r.split(' ').map(n => Number(n))
    let next = colors + 1
    for (let i = 1; i <= next; i++) {
      if (!(~tree[r[0]].indexOf(i)) && !(~tree[r[1]].indexOf(i))) {
        tree[r[0]].push(i)
        tree[r[1]].push(i)
        ans.push(i)
        if (i === colors + 1) colors = i
        break;
      }
    }
  })
  console.log(colors)
  console.log(ans.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
