def resolve():

    N = int(eval(input()))

    g = {}

    edges_to_idx = {}

    edges = []

    for i in range(N-1):

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

        g.setdefault(a-1, [])

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

        g.setdefault(b-1, [])

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

        edges_to_idx.setdefault("{}-{}".format(a-1, b-1), i)

        edges_to_idx.setdefault("{}-{}".format(b-1, a-1), i)

        edges.append((a-1, b-1))



    nodes = [(None, 0)]

    colors = [None for _ in range(N-1)]

    maxdeg = 0

    while nodes:

        prevcol, node = nodes.pop()

        maxdeg = max(maxdeg, len(g[node]))

        idx = 0

        for col in range(1, len(g[node])+1):

            if col == prevcol:

                continue

            nxt = g[node][idx]

            coloridx = edges_to_idx["{}-{}".format(node, nxt)] 

            if colors[coloridx] is not None:

                idx += 1

                if idx >= len(g[node]):

                    break

                nxt = g[node][idx]

                coloridx = edges_to_idx["{}-{}".format(node, nxt)] 

            colors[coloridx] = col

            nodes.append((col, nxt))

            idx += 1

            if idx >= len(g[node]):

                break

            

    

    print(maxdeg)

    for col in colors:

        print(col)

            

            









if '__main__' == __name__:

    resolve()

def resolve():

    N = int(eval(input()))

    g = {}

    for i in range(N-1):

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

        g.setdefault(a-1, [])

        g[a-1].append((b-1, i))

        g.setdefault(b-1, [])

        g[b-1].append((a-1, i))

        

    nodes = [(None, 0)]

    colors = [None for _ in range(N-1)]

    maxdeg = 0

    while nodes:

        prevcol, node = nodes.pop()

        maxdeg = max(maxdeg, len(g[node]))

        color = 1 if prevcol != 1 else 2

        for nxt, colidx in g[node]:

            if colors[colidx] is None:

                colors[colidx] = color

                nodes.append((color, nxt))

                color += 1 if prevcol != color+1 else 2



    print(maxdeg)

    for col in colors:

        print(col)

            







if '__main__' == __name__:

    resolve()

def resolve():
    N = int(eval(input()))
    g = {}
    edges_to_idx = {}
    edges = []
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        g.setdefault(a - 1, [])
        g[a - 1].append(b - 1)
        g.setdefault(b - 1, [])
        g[b - 1].append(a - 1)
        edges_to_idx.setdefault("{}-{}".format(a - 1, b - 1), i)
        edges_to_idx.setdefault("{}-{}".format(b - 1, a - 1), i)
        edges.append((a - 1, b - 1))
    nodes = [(None, 0)]
    colors = [None for _ in range(N - 1)]
    maxdeg = 0
    while nodes:
        prevcol, node = nodes.pop()
        maxdeg = max(maxdeg, len(g[node]))
        idx = 0
        for col in range(1, len(g[node]) + 1):
            if col == prevcol:
                continue
            nxt = g[node][idx]
            coloridx = edges_to_idx["{}-{}".format(node, nxt)]
            if colors[coloridx] is not None:
                idx += 1
                if idx >= len(g[node]):
                    break
                nxt = g[node][idx]
                coloridx = edges_to_idx["{}-{}".format(node, nxt)]
            colors[coloridx] = col
            nodes.append((col, nxt))
            idx += 1
            if idx >= len(g[node]):
                break
    print(maxdeg)
    for col in colors:
        print(col)


if "__main__" == __name__:
    resolve()

def resolve():
    N = int(eval(input()))
    g = {}
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        g.setdefault(a - 1, [])
        g[a - 1].append((b - 1, i))
        g.setdefault(b - 1, [])
        g[b - 1].append((a - 1, i))
    nodes = [(None, 0)]
    colors = [None for _ in range(N - 1)]
    maxdeg = 0
    while nodes:
        prevcol, node = nodes.pop()
        maxdeg = max(maxdeg, len(g[node]))
        color = 1 if prevcol != 1 else 2
        for nxt, colidx in g[node]:
            if colors[colidx] is None:
                colors[colidx] = color
                nodes.append((color, nxt))
                color += 1 if prevcol != color + 1 else 2
    print(maxdeg)
    for col in colors:
        print(col)


if "__main__" == __name__:
    resolve()

-    edges_to_idx = {} -    edges = [] -        g[a - 1].append(b - 1) +        g[a - 1].append((b - 1, i)) -        g[b - 1].append(a - 1) -        edges_to_idx.setdefault("{}-{}".format(a - 1, b - 1), i) -        edges_to_idx.setdefault("{}-{}".format(b - 1, a - 1), i) -        edges.append((a - 1, b - 1)) +        g[b - 1].append((a - 1, i)) -        idx = 0 -        for col in range(1, len(g[node]) + 1): -            if col == prevcol: -                continue -            nxt = g[node][idx] -            coloridx = edges_to_idx["{}-{}".format(node, nxt)] -            if colors[coloridx] is not None: -                idx += 1 -                if idx >= len(g[node]): -                    break -                nxt = g[node][idx] -                coloridx = edges_to_idx["{}-{}".format(node, nxt)] -            colors[coloridx] = col -            nodes.append((col, nxt)) -            idx += 1 -            if idx >= len(g[node]): -                break +        color = 1 if prevcol != 1 else 2 +        for nxt, colidx in g[node]: +            if colors[colidx] is None: +                colors[colidx] = color +                nodes.append((color, nxt)) +                color += 1 if prevcol != color + 1 else 2