import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

def resolve():

    n=int(eval(input()))

    E=[[] for _ in range(n)]

    idx={}

    for i in range(n-1):

        a,b=list(map(int,input().split()))

        a-=1; b-=1

        E[a].append(b)

        E[b].append(a)

        idx[(a,b)]=i



    ans=[None]*(n-1)

    k=max(len(E[v]) for v in range(n))



    # DFSで辺に色付け

    Q=[0]

    while(Q):

        v=Q.pop()

        if(v):

            p=min(E[v]) # 親はE[v]の最小値

            c=ans[idx[(p,v)]] # 親につながる色

        cnt=1

        for nv in E[v]:

            if(v==0):

                ans[idx[(v,nv)]]=cnt

                cnt+=1

                Q.append(nv)

            else:

                if(cnt==c): cnt+=1

                if(nv==p): continue

                ans[idx[(v,nv)]]=cnt

                cnt+=1

                Q.append(nv)



    print(k)

    for c in ans:

        print(c)



resolve()
import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

def resolve():

    n=int(input())

    E=[[] for _ in range(n)]

    idx={}

    for i in range(n-1):

        a,b=map(int,input().split())

        a-=1; b-=1

        E[a].append(b)

        idx[(a,b)]=i

    ans=[None]*(n-1)



    # coloring

    Q=[(0,0)]

    while(Q):

        v,c=Q.pop()

        cnt=1

        for nv in E[v]:

            cnt+=cnt==c # 親との辺の色と被るときは1増やす

            ans[idx[(v,nv)]]=cnt

            Q.append((nv,cnt))

            cnt+=1



    print(max(ans))

    print(*ans,sep='\n')

resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n = int(eval(input()))
    E = [[] for _ in range(n)]
    idx = {}
    for i in range(n - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        E[a].append(b)
        E[b].append(a)
        idx[(a, b)] = i
    ans = [None] * (n - 1)
    k = max(len(E[v]) for v in range(n))
    # DFSで辺に色付け
    Q = [0]
    while Q:
        v = Q.pop()
        if v:
            p = min(E[v])  # 親はE[v]の最小値
            c = ans[idx[(p, v)]]  # 親につながる色
        cnt = 1
        for nv in E[v]:
            if v == 0:
                ans[idx[(v, nv)]] = cnt
                cnt += 1
                Q.append(nv)
            else:
                if cnt == c:
                    cnt += 1
                if nv == p:
                    continue
                ans[idx[(v, nv)]] = cnt
                cnt += 1
                Q.append(nv)
    print(k)
    for c in ans:
        print(c)


resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n = int(input())
    E = [[] for _ in range(n)]
    idx = {}
    for i in range(n - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        E[a].append(b)
        idx[(a, b)] = i
    ans = [None] * (n - 1)
    # coloring
    Q = [(0, 0)]
    while Q:
        v, c = Q.pop()
        cnt = 1
        for nv in E[v]:
            cnt += cnt == c  # 親との辺の色と被るときは1増やす
            ans[idx[(v, nv)]] = cnt
            Q.append((nv, cnt))
            cnt += 1
    print(max(ans))
    print(*ans, sep="\n")


resolve()

-    n = int(eval(input())) +    n = int(input()) -        a, b = list(map(int, input().split())) +        a, b = map(int, input().split()) -        E[b].append(a) -    k = max(len(E[v]) for v in range(n)) -    # DFSで辺に色付け -    Q = [0] +    # coloring +    Q = [(0, 0)] -        v = Q.pop() -        if v: -            p = min(E[v])  # 親はE[v]の最小値 -            c = ans[idx[(p, v)]]  # 親につながる色 +        v, c = Q.pop() -            if v == 0: -                ans[idx[(v, nv)]] = cnt -                cnt += 1 -                Q.append(nv) -            else: -                if cnt == c: -                    cnt += 1 -                if nv == p: -                    continue -                ans[idx[(v, nv)]] = cnt -                cnt += 1 -                Q.append(nv) -    print(k) -    for c in ans: -        print(c) +            cnt += cnt == c  # 親との辺の色と被るときは1増やす +            ans[idx[(v, nv)]] = cnt +            Q.append((nv, cnt)) +            cnt += 1 +    print(max(ans)) +    print(*ans, sep="\n")