import sys

from collections import deque

input = sys.stdin.readline

N = int(eval(input()))

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

ab = [list([int(x)-1 for x in input().split()]) for _ in range(N-1)]



col_max = 0

for i in range(N-1):

  a, b = ab[i]

  graph[a] += [b]

  graph[b] += [a]



for i in range(N):

  col_max = max(col_max, len(graph[i]))

print(col_max)



def bfs(s):

  q = deque([s])

  col = [-1]*N

  col[s] = 0

  edge_col = {}



  while q:

    c = 1

    u = q.pop()

    for v in graph[u]:

      if col[v] == -1:

        if c == col[u]:

          c += 1

        col[v] = c

        q.append(v)

        edge_col[(u, v)] = c

        edge_col[(v, u)] = c

        c += 1

  return edge_col



col = bfs(0)



for a, b in ab:

  print((col[(a, b)]))
import sys

sys.setrecursionlimit(1000000000)

input = sys.stdin.readline

N = int(eval(input()))

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

ab = [list([int(x)-1 for x in input().split()]) for _ in range(N-1)]

d = {}



for a, b in ab:

  graph[a] += [b]

  graph[b] += [a]



def dfs(u, pre, c):

  color = 0

  for v in graph[u]:

    if v != pre:

      color += 1

      if color == c:

        color += 1

      d[(u, v)] = color

      d[(v, u)] = color

      dfs(v, u, color)



dfs(0, -1, -1)

s = set()

for a, b in ab:

  s.add(d[(a, b)])



print((len(s)))

for a, b in ab:

  print((d[(a, b)]))

  

import sys
from collections import deque

input = sys.stdin.readline
N = int(eval(input()))
graph = [[] for _ in range(N)]
ab = [list([int(x) - 1 for x in input().split()]) for _ in range(N - 1)]
col_max = 0
for i in range(N - 1):
    a, b = ab[i]
    graph[a] += [b]
    graph[b] += [a]
for i in range(N):
    col_max = max(col_max, len(graph[i]))
print(col_max)


def bfs(s):
    q = deque([s])
    col = [-1] * N
    col[s] = 0
    edge_col = {}
    while q:
        c = 1
        u = q.pop()
        for v in graph[u]:
            if col[v] == -1:
                if c == col[u]:
                    c += 1
                col[v] = c
                q.append(v)
                edge_col[(u, v)] = c
                edge_col[(v, u)] = c
                c += 1
    return edge_col


col = bfs(0)
for a, b in ab:
    print((col[(a, b)]))

import sys

sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
N = int(eval(input()))
graph = [[] for _ in range(N)]
ab = [list([int(x) - 1 for x in input().split()]) for _ in range(N - 1)]
d = {}
for a, b in ab:
    graph[a] += [b]
    graph[b] += [a]


def dfs(u, pre, c):
    color = 0
    for v in graph[u]:
        if v != pre:
            color += 1
            if color == c:
                color += 1
            d[(u, v)] = color
            d[(v, u)] = color
            dfs(v, u, color)


dfs(0, -1, -1)
s = set()
for a, b in ab:
    s.add(d[(a, b)])
print((len(s)))
for a, b in ab:
    print((d[(a, b)]))

-from collections import deque +sys.setrecursionlimit(1000000000) -col_max = 0 -for i in range(N - 1): -    a, b = ab[i] +d = {} +for a, b in ab: -for i in range(N): -    col_max = max(col_max, len(graph[i])) -print(col_max) -def bfs(s): -    q = deque([s]) -    col = [-1] * N -    col[s] = 0 -    edge_col = {} -    while q: -        c = 1 -        u = q.pop() -        for v in graph[u]: -            if col[v] == -1: -                if c == col[u]: -                    c += 1 -                col[v] = c -                q.append(v) -                edge_col[(u, v)] = c -                edge_col[(v, u)] = c -                c += 1 -    return edge_col +def dfs(u, pre, c): +    color = 0 +    for v in graph[u]: +        if v != pre: +            color += 1 +            if color == c: +                color += 1 +            d[(u, v)] = color +            d[(v, u)] = color +            dfs(v, u, color) -col = bfs(0) +dfs(0, -1, -1) +s = set() -    print((col[(a, b)])) +    s.add(d[(a, b)]) +print((len(s))) +for a, b in ab: +    print((d[(a, b)]))