import sys

sys.setrecursionlimit(10**9)

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

inpl = lambda: list(map(int,input().split()))

N = int(eval(input()))

edge = [set() for _ in range(N)]

ab = []

for i in range(N-1):

    a, b = inpl()

    a -= 1

    b -= 1

    ab.append((a,b))

    edge[a].add(i)

    edge[b].add(i)



K = 0

ans = [0]*(N-1)

def dfs(node, prev=0):

    global K

    c = 0

    for i in edge[node]:

        c += 1

        if c == prev:

            c += 1

        a, b = ab[i]

        if node == a:

            x = b

        else:

            x = a

        edge[x].remove(i)

        ans[i] = c

        dfs(x, c)

    if c >= K:

        K = c



dfs(0)

print(K)

for i in range(N-1):

    print((ans[i]))

import sys

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

inpl = lambda: list(map(int,input().split()))

N = int(eval(input()))

edge = [set() for _ in range(N)]

ab = []

for i in range(N-1):

    a, b = inpl()

    a -= 1

    b -= 1

    ab.append((a,b))

    edge[a].add(i)

    edge[b].add(i)



K = 0

ans = [0]*(N-1)

pool = [(0,0)]

while pool:

    node, prev = pool.pop()

    c = 0

    for i in edge[node]:

        c += 1

        if c == prev:

            c += 1

        a, b = ab[i]

        if node == a:

            x = b

        else:

            x = a

        edge[x].remove(i)

        ans[i] = c

        pool.append((x,c))

    if c >= K:

        K = c



print(K)

for i in range(N-1):

    print((ans[i]))

import sys

sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
edge = [set() for _ in range(N)]
ab = []
for i in range(N - 1):
    a, b = inpl()
    a -= 1
    b -= 1
    ab.append((a, b))
    edge[a].add(i)
    edge[b].add(i)
K = 0
ans = [0] * (N - 1)


def dfs(node, prev=0):
    global K
    c = 0
    for i in edge[node]:
        c += 1
        if c == prev:
            c += 1
        a, b = ab[i]
        if node == a:
            x = b
        else:
            x = a
        edge[x].remove(i)
        ans[i] = c
        dfs(x, c)
    if c >= K:
        K = c


dfs(0)
print(K)
for i in range(N - 1):
    print((ans[i]))

import sys

input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
edge = [set() for _ in range(N)]
ab = []
for i in range(N - 1):
    a, b = inpl()
    a -= 1
    b -= 1
    ab.append((a, b))
    edge[a].add(i)
    edge[b].add(i)
K = 0
ans = [0] * (N - 1)
pool = [(0, 0)]
while pool:
    node, prev = pool.pop()
    c = 0
    for i in edge[node]:
        c += 1
        if c == prev:
            c += 1
        a, b = ab[i]
        if node == a:
            x = b
        else:
            x = a
        edge[x].remove(i)
        ans[i] = c
        pool.append((x, c))
    if c >= K:
        K = c
print(K)
for i in range(N - 1):
    print((ans[i]))

-sys.setrecursionlimit(10**9) - - -def dfs(node, prev=0): -    global K +pool = [(0, 0)] +while pool: +    node, prev = pool.pop() -        dfs(x, c) +        pool.append((x, c)) - - -dfs(0)