def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]



from collections import defaultdict, deque

from sys import exit

import math

import copy

from bisect import bisect_left



import sys

# sys.setrecursionlimit(1000000)

# list(map(int, input().split()))

mod = 10 ** 9 + 7



from collections import deque



# まず、Kの最小値を求める

#　頂点に繋がる辺の数 <= Kを全ての頂点で満たす

N = getN()

dist = [[] for i in range(N + 1)]

# エッジの配列はこうする

edge = {}

for i in range(N - 1):

    a, b = getNM()

    dist[a].append(b)

    dist[b].append(a)

    # エッジの色の入力の仕方

    edge[(a, b)] = i

    edge[(b, a)] = i



ignore = [-1] * (N + 1)

ignore[1] = 0

# 辺の数は頂点の数より一つ少ない

ans = [0] * (N - 1)



pos = deque([1])

while len(pos) > 0:

    u = pos.popleft()

    # 一番最初の色から順にサーチしていく

    j = 1

    for i in dist[u]:

        if ignore[i] < 0:

            # 根元の頂点の色と一致していたら色を変える

            if j == ignore[u]:

                j += 1

            # 辺をスライドしていくたびに行先の頂点の色を変える

            ignore[i] = j

            # 辺の色は行先の頂点の色に合わせる

            ans[edge[(i, u)]] = j

            pos.append(i)

            j += 1

print((max(ans)))

for a in ans:

    print(a)
def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)



def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)



from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

import math

from fractions import gcd

import random

import string

import copy

from itertools import combinations, permutations, product

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7



#############

# Main Code #

#############



N = getN()

dist = [[] for i in range(N)]

edge = {}

for i in range(N - 1):

    a, b = getNM()

    dist[a - 1].append(b - 1)

    dist[b - 1].append(a - 1)

    # queryの何番目のエッジか

    edge[(a - 1, b - 1)] = i

    edge[(b - 1, a - 1)] = i



ignore = [-1] * N

ignore[0] = 0

ans = [0] * (N - 1)



pos = deque([0])

while len(pos) > 0:

    u = pos.popleft()

    j = 1

    for i in dist[u]:

        if ignore[i] < 0:

            if j == ignore[u]:

                j += 1

            ignore[i] = j

            ans[edge[(i, u)]] = j

            pos.append(i)

            j += 1

print((max(ans)))

for i in ans:

    print(i)
def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left
import sys

# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
mod = 10**9 + 7
from collections import deque

# まず、Kの最小値を求める
# 　頂点に繋がる辺の数 <= Kを全ての頂点で満たす
N = getN()
dist = [[] for i in range(N + 1)]
# エッジの配列はこうする
edge = {}
for i in range(N - 1):
    a, b = getNM()
    dist[a].append(b)
    dist[b].append(a)
    # エッジの色の入力の仕方
    edge[(a, b)] = i
    edge[(b, a)] = i
ignore = [-1] * (N + 1)
ignore[1] = 0
# 辺の数は頂点の数より一つ少ない
ans = [0] * (N - 1)
pos = deque([1])
while len(pos) > 0:
    u = pos.popleft()
    # 一番最初の色から順にサーチしていく
    j = 1
    for i in dist[u]:
        if ignore[i] < 0:
            # 根元の頂点の色と一致していたら色を変える
            if j == ignore[u]:
                j += 1
            # 辺をスライドしていくたびに行先の頂点の色を変える
            ignore[i] = j
            # 辺の色は行先の頂点の色に合わせる
            ans[edge[(i, u)]] = j
            pos.append(i)
            j += 1
print((max(ans)))
for a in ans:
    print(a)

def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


def input():
    return sys.stdin.readline().rstrip()


def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)


def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]


def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)


def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)


from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N = getN()
dist = [[] for i in range(N)]
edge = {}
for i in range(N - 1):
    a, b = getNM()
    dist[a - 1].append(b - 1)
    dist[b - 1].append(a - 1)
    # queryの何番目のエッジか
    edge[(a - 1, b - 1)] = i
    edge[(b - 1, a - 1)] = i
ignore = [-1] * N
ignore[0] = 0
ans = [0] * (N - 1)
pos = deque([0])
while len(pos) > 0:
    u = pos.popleft()
    j = 1
    for i in dist[u]:
        if ignore[i] < 0:
            if j == ignore[u]:
                j += 1
            ignore[i] = j
            ans[edge[(i, u)]] = j
            pos.append(i)
            j += 1
print((max(ans)))
for i in ans:
    print(i)

-from collections import defaultdict, deque +def input(): +    return sys.stdin.readline().rstrip() + + +def rand_N(ran1, ran2): +    return random.randint(ran1, ran2) + + +def rand_List(ran1, ran2, rantime): +    return [random.randint(ran1, ran2) for i in range(rantime)] + + +def rand_ints_nodup(ran1, ran2, rantime): +    ns = [] +    while len(ns) < rantime: +        n = random.randint(ran1, ran2) +        if not n in ns: +            ns.append(n) +    return sorted(ns) + + +def rand_query(ran1, ran2, rantime): +    r_query = [] +    while len(r_query) < rantime: +        n_q = rand_ints_nodup(ran1, ran2, 2) +        if not n_q in r_query: +            r_query.append(n_q) +    return sorted(r_query) + + +from collections import defaultdict, deque, Counter +from decimal import * +import heapq +from fractions import gcd +import random +import string -from bisect import bisect_left +from itertools import combinations, permutations, product +from operator import mul +from functools import reduce +from bisect import bisect_left, bisect_right -# sys.setrecursionlimit(1000000) -# list(map(int, input().split())) +sys.setrecursionlimit(1000000000) -from collections import deque - -# まず、Kの最小値を求める -# 　頂点に繋がる辺の数 <= Kを全ての頂点で満たす +############# +# Main Code # +############# -dist = [[] for i in range(N + 1)] -# エッジの配列はこうする +dist = [[] for i in range(N)] -    dist[a].append(b) -    dist[b].append(a) -    # エッジの色の入力の仕方 -    edge[(a, b)] = i -    edge[(b, a)] = i -ignore = [-1] * (N + 1) -ignore[1] = 0 -# 辺の数は頂点の数より一つ少ない +    dist[a - 1].append(b - 1) +    dist[b - 1].append(a - 1) +    # queryの何番目のエッジか +    edge[(a - 1, b - 1)] = i +    edge[(b - 1, a - 1)] = i +ignore = [-1] * N +ignore[0] = 0 -pos = deque([1]) +pos = deque([0]) -    # 一番最初の色から順にサーチしていく -            # 根元の頂点の色と一致していたら色を変える -            # 辺をスライドしていくたびに行先の頂点の色を変える -            # 辺の色は行先の頂点の色に合わせる -for a in ans: -    print(a) +for i in ans: +    print(i)