# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく

# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す

# グラフ構築の際に、辺の番号を持っておく



import sys

readline = sys.stdin.readline



N = int(readline())

G = [[] for i in range(N)]

for i in range(N - 1):

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

  G[a-1].append([b-1,i])

  G[b-1].append([a-1,i])

  

ans = [0 for i in range(N - 1)]

from collections import deque

# 頂点、親から来た色、親

q = deque([[0, 0, -1]])

while q:

  v,pcol,parent = q.popleft()

  cnt = 1

  for child in G[v]:

    if child[0] == parent:

      continue

    if cnt == pcol:

      cnt += 1

    ans[child[1]] = cnt

    q.append([child[0],cnt,v])

    cnt += 1



print((max(ans)))

for a in ans:

  print(a)
import sys

readline = sys.stdin.readline



N = int(readline())



G = [[] for i in range(N)]

from collections import defaultdict

E = defaultdict(int)



for i in range(N - 1):

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

  G[a - 1].append(b - 1)

  G[b - 1].append(a - 1)

  E[(a - 1, b - 1)] = i



from collections import deque

q = deque([])

ans = [None] * (N - 1)



q.append([0, -1, 0])

maxcol = 0

while q:

  v, parent, color = q.popleft()

  if color > maxcol:

    maxcol = color

  if (v, parent) in E:

    ans[E[(v, parent)]] = color

  elif (parent, v) in E:

    ans[E[(parent, v)]] = color

  next_col = 0

  for child in G[v]:

    if child == parent:

      continue

    next_col += 1

    if next_col == color:

      next_col += 1

    q.append([child, v, next_col])

    

print(maxcol)

for a in ans:

  print(a)
# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく
# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す
# グラフ構築の際に、辺の番号を持っておく
import sys

readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b = list(map(int, readline().split()))
    G[a - 1].append([b - 1, i])
    G[b - 1].append([a - 1, i])
ans = [0 for i in range(N - 1)]
from collections import deque

# 頂点、親から来た色、親
q = deque([[0, 0, -1]])
while q:
    v, pcol, parent = q.popleft()
    cnt = 1
    for child in G[v]:
        if child[0] == parent:
            continue
        if cnt == pcol:
            cnt += 1
        ans[child[1]] = cnt
        q.append([child[0], cnt, v])
        cnt += 1
print((max(ans)))
for a in ans:
    print(a)

import sys

readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
from collections import defaultdict

E = defaultdict(int)
for i in range(N - 1):
    a, b = list(map(int, readline().split()))
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
    E[(a - 1, b - 1)] = i
from collections import deque

q = deque([])
ans = [None] * (N - 1)
q.append([0, -1, 0])
maxcol = 0
while q:
    v, parent, color = q.popleft()
    if color > maxcol:
        maxcol = color
    if (v, parent) in E:
        ans[E[(v, parent)]] = color
    elif (parent, v) in E:
        ans[E[(parent, v)]] = color
    next_col = 0
    for child in G[v]:
        if child == parent:
            continue
        next_col += 1
        if next_col == color:
            next_col += 1
        q.append([child, v, next_col])
print(maxcol)
for a in ans:
    print(a)

-# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく -# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す -# グラフ構築の際に、辺の番号を持っておく +from collections import defaultdict + +E = defaultdict(int) -    G[a - 1].append([b - 1, i]) -    G[b - 1].append([a - 1, i]) -ans = [0 for i in range(N - 1)] +    G[a - 1].append(b - 1) +    G[b - 1].append(a - 1) +    E[(a - 1, b - 1)] = i -# 頂点、親から来た色、親 -q = deque([[0, 0, -1]]) +q = deque([]) +ans = [None] * (N - 1) +q.append([0, -1, 0]) +maxcol = 0 -    v, pcol, parent = q.popleft() -    cnt = 1 +    v, parent, color = q.popleft() +    if color > maxcol: +        maxcol = color +    if (v, parent) in E: +        ans[E[(v, parent)]] = color +    elif (parent, v) in E: +        ans[E[(parent, v)]] = color +    next_col = 0 -        if child[0] == parent: +        if child == parent: -        if cnt == pcol: -            cnt += 1 -        ans[child[1]] = cnt -        q.append([child[0], cnt, v]) -        cnt += 1 -print((max(ans))) +        next_col += 1 +        if next_col == color: +            next_col += 1 +        q.append([child, v, next_col]) +print(maxcol)