import sys

input = sys.stdin.readline





n = int(eval(input()))



GRAPH = {i:[] for i in range(1, n + 1)}

EDGES = []

for _ in range(n - 1):

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

    GRAPH[a].append(b)

    GRAPH[b].append(a)

    EDGES.append((a, b))



PREV = {1:0}

Q = [1]

while Q:

    now = Q.pop(0)

    for vertex in GRAPH[now]:

        if vertex == PREV[now]:

            continue

        next = vertex

        PREV[next] = now

        Q.append(next)



COLORS = {(0, 1):0}

Q = [1]

while Q:

    now = Q.pop(0)

    prev = PREV[now]

    a, b = min(now, prev), max(now, prev)

    used = COLORS[(a, b)]

    

    color = 1

    for vertex in GRAPH[now]:

        if vertex == prev:

            continue

        next = vertex

        a, b = min(now, next), max(now, next)

        if color == used:

            color += 1

            COLORS[(a, b)] = color

            color += 1

        else:

            COLORS[(a, b)] = color

            color += 1

        Q.append(next)



print((max(COLORS.values())))

for edge in EDGES:

    print((COLORS[edge]))

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**9)





n = int(eval(input()))



GRAPH = {i:[] for i in range(1, n + 1)}

EDGES = []

for _ in range(n - 1):

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

    GRAPH[a].append(b)

    GRAPH[b].append(a)

    EDGES.append((a, b))



def dfs(now, prev = 0):

    a, b = min(now, prev), max(now, prev)

    used = COLORS[(a, b)]

    color = 1

    for v in GRAPH[now]:

        if v == prev:

            continue

        next = v

        a, b = min(now, next), max(now, next)

        if color == used:

            color += 1

            COLORS[(a, b)] = color

            color += 1

        else:

            COLORS[(a, b)] = color

            color += 1

    

    for v in GRAPH[now]:

        if v == prev:

            continue

        next = v

        dfs(next, now)



COLORS = {(0, 1):0}

dfs(1)



print((max(COLORS.values())))

for edge in EDGES:

    print((COLORS[edge]))

import sys

input = sys.stdin.readline
n = int(eval(input()))
GRAPH = {i: [] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    GRAPH[a].append(b)
    GRAPH[b].append(a)
    EDGES.append((a, b))
PREV = {1: 0}
Q = [1]
while Q:
    now = Q.pop(0)
    for vertex in GRAPH[now]:
        if vertex == PREV[now]:
            continue
        next = vertex
        PREV[next] = now
        Q.append(next)
COLORS = {(0, 1): 0}
Q = [1]
while Q:
    now = Q.pop(0)
    prev = PREV[now]
    a, b = min(now, prev), max(now, prev)
    used = COLORS[(a, b)]
    color = 1
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        next = vertex
        a, b = min(now, next), max(now, next)
        if color == used:
            color += 1
            COLORS[(a, b)] = color
            color += 1
        else:
            COLORS[(a, b)] = color
            color += 1
        Q.append(next)
print((max(COLORS.values())))
for edge in EDGES:
    print((COLORS[edge]))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n = int(eval(input()))
GRAPH = {i: [] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    GRAPH[a].append(b)
    GRAPH[b].append(a)
    EDGES.append((a, b))


def dfs(now, prev=0):
    a, b = min(now, prev), max(now, prev)
    used = COLORS[(a, b)]
    color = 1
    for v in GRAPH[now]:
        if v == prev:
            continue
        next = v
        a, b = min(now, next), max(now, next)
        if color == used:
            color += 1
            COLORS[(a, b)] = color
            color += 1
        else:
            COLORS[(a, b)] = color
            color += 1
    for v in GRAPH[now]:
        if v == prev:
            continue
        next = v
        dfs(next, now)


COLORS = {(0, 1): 0}
dfs(1)
print((max(COLORS.values())))
for edge in EDGES:
    print((COLORS[edge]))

+sys.setrecursionlimit(10**9) -PREV = {1: 0} -Q = [1] -while Q: -    now = Q.pop(0) -    for vertex in GRAPH[now]: -        if vertex == PREV[now]: -            continue -        next = vertex -        PREV[next] = now -        Q.append(next) -COLORS = {(0, 1): 0} -Q = [1] -while Q: -    now = Q.pop(0) -    prev = PREV[now] + + +def dfs(now, prev=0): -    for vertex in GRAPH[now]: -        if vertex == prev: +    for v in GRAPH[now]: +        if v == prev: -        next = vertex +        next = v -        Q.append(next) +    for v in GRAPH[now]: +        if v == prev: +            continue +        next = v +        dfs(next, now) + + +COLORS = {(0, 1): 0} +dfs(1)