def main():

    n=int(eval(input()))

    ab=[list(map(int,input().split())) for _ in [0]*(n-1)]

    g=[[] for _ in [0]*n]

    [g[a-1].append(b-1) for a,b in ab]

    [g[b-1].append(a-1) for a,b in ab]

    color=[-1]*n

    color[0]=0

    q=[[0,0]]

    while q:

        qq=[]

        while q:

            i,root=q.pop()

            cnt=1

            for j in g[i]:

                if j==root:

                    continue

                if cnt==color[i]:

                    cnt+=1

                color[j]=cnt

                cnt+=1

                qq.append([j,i])

        q=qq

    print((max(color[1:])))

    for i,j in ab:

        print((color[j-1]))

main()
def main():

    n=int(eval(input()))

    ab=[list(map(int,input().split())) for _ in [0]*(n-1)]

    g=[[] for _ in [0]*n]

    [g[a-1].append(b-1) for a,b in ab]

    [g[b-1].append(a-1) for a,b in ab]

    color=[-1]*n

    color[0]=0

    q=[[0,0]]

    while q:

        qq=[]

        while q:

            i,root=q.pop()

            cnt=1

            for j in g[i]:

                if j==root:

                    continue

                if cnt==color[i]:

                    cnt+=1

                color[j]=cnt

                cnt+=1

                qq.append([j,i])

        q=qq

    d=[-1]*n

    d[0]=0

    q=[0]

    cnt=0

    while q:

        qq=[]

        cnt+=1

        while q:

            i=q.pop()

            for j in g[i]:

                if d[j]==-1:

                    d[j]=cnt

                    qq.append(j)

        q=qq

    print((max(color[1:])))

    for i,j in ab:

        if d[i-1]>d[j-1]:

            k=i

        else:

            k=j

        print((color[k-1]))

main()
def main():
    n = int(eval(input()))
    ab = [list(map(int, input().split())) for _ in [0] * (n - 1)]
    g = [[] for _ in [0] * n]
    [g[a - 1].append(b - 1) for a, b in ab]
    [g[b - 1].append(a - 1) for a, b in ab]
    color = [-1] * n
    color[0] = 0
    q = [[0, 0]]
    while q:
        qq = []
        while q:
            i, root = q.pop()
            cnt = 1
            for j in g[i]:
                if j == root:
                    continue
                if cnt == color[i]:
                    cnt += 1
                color[j] = cnt
                cnt += 1
                qq.append([j, i])
        q = qq
    print((max(color[1:])))
    for i, j in ab:
        print((color[j - 1]))


main()

def main():
    n = int(eval(input()))
    ab = [list(map(int, input().split())) for _ in [0] * (n - 1)]
    g = [[] for _ in [0] * n]
    [g[a - 1].append(b - 1) for a, b in ab]
    [g[b - 1].append(a - 1) for a, b in ab]
    color = [-1] * n
    color[0] = 0
    q = [[0, 0]]
    while q:
        qq = []
        while q:
            i, root = q.pop()
            cnt = 1
            for j in g[i]:
                if j == root:
                    continue
                if cnt == color[i]:
                    cnt += 1
                color[j] = cnt
                cnt += 1
                qq.append([j, i])
        q = qq
    d = [-1] * n
    d[0] = 0
    q = [0]
    cnt = 0
    while q:
        qq = []
        cnt += 1
        while q:
            i = q.pop()
            for j in g[i]:
                if d[j] == -1:
                    d[j] = cnt
                    qq.append(j)
        q = qq
    print((max(color[1:])))
    for i, j in ab:
        if d[i - 1] > d[j - 1]:
            k = i
        else:
            k = j
        print((color[k - 1]))


main()

+    d = [-1] * n +    d[0] = 0 +    q = [0] +    cnt = 0 +    while q: +        qq = [] +        cnt += 1 +        while q: +            i = q.pop() +            for j in g[i]: +                if d[j] == -1: +                    d[j] = cnt +                    qq.append(j) +        q = qq -        print((color[j - 1])) +        if d[i - 1] > d[j - 1]: +            k = i +        else: +            k = j +        print((color[k - 1]))