import sys

sys.setrecursionlimit(10 ** 6)





def dfs(v, c):

    nc = 0

    k = 0

    for nv, idx in edge[v]:

        if status[nv] == 0:

            nc = nc + 1 + ((nc + 1) == c)

            color[idx] = nc

            status[nv] = 1

            k = max(k, dfs(nv, nc))

    return max(nc, k)





N = int(eval(input()))

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

for idx, line in enumerate(sys.stdin.readlines()):

    a, b = [int(x) - 1 for x in line.split()]

    edge[a].append((b, idx))

    edge[b].append((a, idx))



status = [0] * N

color = [0] * (N - 1)

status[0] = 1

K = dfs(0, 0)



print(K)

for c in color:

    print(c)

import sys

from collections import deque





N = int(input())

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

for i, s in enumerate(sys.stdin.readlines()):

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

    a -= 1; b -= 1

    edge[a].append((b, i))

    edge[b].append((a, i))





path = [None] * (N - 1)

q = deque()

q.append((0, 0))



while q:

    v, pc = q.popleft()

    c = 1

    for nv, i in edge[v]:

        if path[i] is None:

            c = c + 1 if c == pc else c

            path[i] = c

            q.append((nv, c))

            c += 1



print(max(path))

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

import sys

sys.setrecursionlimit(10**6)


def dfs(v, c):
    nc = 0
    k = 0
    for nv, idx in edge[v]:
        if status[nv] == 0:
            nc = nc + 1 + ((nc + 1) == c)
            color[idx] = nc
            status[nv] = 1
            k = max(k, dfs(nv, nc))
    return max(nc, k)


N = int(eval(input()))
edge = [[] for _ in range(N)]
for idx, line in enumerate(sys.stdin.readlines()):
    a, b = [int(x) - 1 for x in line.split()]
    edge[a].append((b, idx))
    edge[b].append((a, idx))
status = [0] * N
color = [0] * (N - 1)
status[0] = 1
K = dfs(0, 0)
print(K)
for c in color:
    print(c)

import sys
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for i, s in enumerate(sys.stdin.readlines()):
    a, b = map(int, s.split())
    a -= 1
    b -= 1
    edge[a].append((b, i))
    edge[b].append((a, i))
path = [None] * (N - 1)
q = deque()
q.append((0, 0))
while q:
    v, pc = q.popleft()
    c = 1
    for nv, i in edge[v]:
        if path[i] is None:
            c = c + 1 if c == pc else c
            path[i] = c
            q.append((nv, c))
            c += 1
print(max(path))
print(*path, sep="\n")

+from collections import deque -sys.setrecursionlimit(10**6) - - -def dfs(v, c): -    nc = 0 -    k = 0 -    for nv, idx in edge[v]: -        if status[nv] == 0: -            nc = nc + 1 + ((nc + 1) == c) -            color[idx] = nc -            status[nv] = 1 -            k = max(k, dfs(nv, nc)) -    return max(nc, k) - - -N = int(eval(input())) +N = int(input()) -for idx, line in enumerate(sys.stdin.readlines()): -    a, b = [int(x) - 1 for x in line.split()] -    edge[a].append((b, idx)) -    edge[b].append((a, idx)) -status = [0] * N -color = [0] * (N - 1) -status[0] = 1 -K = dfs(0, 0) -print(K) -for c in color: -    print(c) +for i, s in enumerate(sys.stdin.readlines()): +    a, b = map(int, s.split()) +    a -= 1 +    b -= 1 +    edge[a].append((b, i)) +    edge[b].append((a, i)) +path = [None] * (N - 1) +q = deque() +q.append((0, 0)) +while q: +    v, pc = q.popleft() +    c = 1 +    for nv, i in edge[v]: +        if path[i] is None: +            c = c + 1 if c == pc else c +            path[i] = c +            q.append((nv, c)) +            c += 1 +print(max(path)) +print(*path, sep="\n")