N = int(eval(input()))

AB = [list(map(int, input().split())) for _ in range(N - 1)]



graph = [[] for _ in range(N + 1)]

for a, b in AB:

  graph[a].append(b)

  graph[b].append(a)

#print("graph:", graph)



order = []

stack = [1]

parent = [0] * (N + 1)



while stack:

  s = stack.pop()

  order.append(s)

  for g in graph[s]:

    if parent[s] == g:

      continue

    else:

      parent[g] = s

      stack.append(g)

#print("order:", order)

#print("parent:", parent)



color = [-1] * (N + 1)



for e in order:

  ng = color[e]

  c = 1

  for g in graph[e]:

    if parent[e] == g:

      continue

    if c == ng:

      c += 1

    color[g] = c

    c += 1

#print("color:", color)



print((max(color[2:])))

for a, b in AB:

  if parent[a] == b:

    print((color[a]))

  else:

    print((color[b]))
import sys

input = sys.stdin.buffer.readline



N = int(eval(input()))

AB = [list(map(int, input().split())) for _ in range(N - 1)]



graph = [[] for _ in range(N + 1)]

for a, b in AB:

    graph[a].append(b)

    graph[b].append(a)

  

def make_tree(graph, root) -> (list, list, list):

    INF = 10 ** 15

    dist = [INF] * len(graph)

    parent = [-1] * len(graph)

    stack = [root]

    dist[root] = 0

    order = []

    parent[root] = root

    while stack:

        s = stack.pop()

        order.append(s)

        for g in graph[s]:

            if dist[g] > dist[s] + 1:

                dist[g] = dist[s] + 1

                parent[g] = s

                stack.append(g)

    return dist, parent, order

    

dist, parent, order = make_tree(graph, 1)



color = [-1] * (N + 1)

for s in order:

    ng = color[s]

    c = 1

    for g in graph[s]:

        if parent[s] == g:

            continue

        if c == ng:

            c += 1

        color[g] = c

        c += 1



answer = []

for a, b in AB:

    if parent[a] == b:

        answer.append(color[a])

    else:

        answer.append(color[b])



print((max(answer)))

for a in answer:

    print(a)
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
# print("graph:", graph)
order = []
stack = [1]
parent = [0] * (N + 1)
while stack:
    s = stack.pop()
    order.append(s)
    for g in graph[s]:
        if parent[s] == g:
            continue
        else:
            parent[g] = s
            stack.append(g)
# print("order:", order)
# print("parent:", parent)
color = [-1] * (N + 1)
for e in order:
    ng = color[e]
    c = 1
    for g in graph[e]:
        if parent[e] == g:
            continue
        if c == ng:
            c += 1
        color[g] = c
        c += 1
# print("color:", color)
print((max(color[2:])))
for a, b in AB:
    if parent[a] == b:
        print((color[a]))
    else:
        print((color[b]))

import sys

input = sys.stdin.buffer.readline
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


def make_tree(graph, root) -> (list, list, list):
    INF = 10**15
    dist = [INF] * len(graph)
    parent = [-1] * len(graph)
    stack = [root]
    dist[root] = 0
    order = []
    parent[root] = root
    while stack:
        s = stack.pop()
        order.append(s)
        for g in graph[s]:
            if dist[g] > dist[s] + 1:
                dist[g] = dist[s] + 1
                parent[g] = s
                stack.append(g)
    return dist, parent, order


dist, parent, order = make_tree(graph, 1)
color = [-1] * (N + 1)
for s in order:
    ng = color[s]
    c = 1
    for g in graph[s]:
        if parent[s] == g:
            continue
        if c == ng:
            c += 1
        color[g] = c
        c += 1
answer = []
for a, b in AB:
    if parent[a] == b:
        answer.append(color[a])
    else:
        answer.append(color[b])
print((max(answer)))
for a in answer:
    print(a)

+import sys + +input = sys.stdin.buffer.readline -# print("graph:", graph) -order = [] -stack = [1] -parent = [0] * (N + 1) -while stack: -    s = stack.pop() -    order.append(s) + + +def make_tree(graph, root) -> (list, list, list): +    INF = 10**15 +    dist = [INF] * len(graph) +    parent = [-1] * len(graph) +    stack = [root] +    dist[root] = 0 +    order = [] +    parent[root] = root +    while stack: +        s = stack.pop() +        order.append(s) +        for g in graph[s]: +            if dist[g] > dist[s] + 1: +                dist[g] = dist[s] + 1 +                parent[g] = s +                stack.append(g) +    return dist, parent, order + + +dist, parent, order = make_tree(graph, 1) +color = [-1] * (N + 1) +for s in order: +    ng = color[s] +    c = 1 -            continue -        else: -            parent[g] = s -            stack.append(g) -# print("order:", order) -# print("parent:", parent) -color = [-1] * (N + 1) -for e in order: -    ng = color[e] -    c = 1 -    for g in graph[e]: -        if parent[e] == g: -# print("color:", color) -print((max(color[2:]))) +answer = [] -        print((color[a])) +        answer.append(color[a]) -        print((color[b])) +        answer.append(color[b]) +print((max(answer))) +for a in answer: +    print(a)