import sys

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict as dd

input = sys.stdin.readline

N = int(eval(input()))

e = dd(list)

for i in range(N - 1):

  a, b = tuple(map(int, input().split()))

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

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

res = [0] * (N - 1)

vis = set()

def dfs(x):

  global vis

  global res

  viss = set()

  svis = set()

  t = 1

  for y, i in e[x]:

    if i in vis: viss.add(res[i])

  #print(x, viss)

  for y, i in e[x]:

    #print(x, y, t)

    while t in viss:

      t += 1

    if i in vis:

      continue

    #print(x, y, t)

    svis.add(y)

    vis.add(i)

    res[i] = t

    t += 1

    dfs(y)

  #print(res)

dfs(1)

print((max(res)))

for r in res: print(r)
import sys

from collections import defaultdict as dd

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 6)

N = int(eval(input()))

e = dd(list)

for i in range(N - 1):

  u, v = list(map(int, input().split()))

  e[u].append((v, i))

  e[v].append((u, i))

res = [0] * (N - 1)

def dfs(x):

  global res

  c = 1

  vis = set()

  for y, i in e[x]: vis.add(res[i])

  #print(x, vis)

  for y, i in e[x]:

    if res[i] > 0: continue

    while c in vis: c += 1

    #print(x, c)

    res[i] = c

    vis.add(c)

    dfs(y)

dfs(1)

print((max(res)))

for r in res: print(r)
import sys

sys.setrecursionlimit(10**7)
from collections import defaultdict as dd

input = sys.stdin.readline
N = int(eval(input()))
e = dd(list)
for i in range(N - 1):
    a, b = tuple(map(int, input().split()))
    e[a].append((b, i))
    e[b].append((a, i))
res = [0] * (N - 1)
vis = set()


def dfs(x):
    global vis
    global res
    viss = set()
    svis = set()
    t = 1
    for y, i in e[x]:
        if i in vis:
            viss.add(res[i])
    # print(x, viss)
    for y, i in e[x]:
        # print(x, y, t)
        while t in viss:
            t += 1
        if i in vis:
            continue
        # print(x, y, t)
        svis.add(y)
        vis.add(i)
        res[i] = t
        t += 1
        dfs(y)
    # print(res)


dfs(1)
print((max(res)))
for r in res:
    print(r)

import sys
from collections import defaultdict as dd

input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(eval(input()))
e = dd(list)
for i in range(N - 1):
    u, v = list(map(int, input().split()))
    e[u].append((v, i))
    e[v].append((u, i))
res = [0] * (N - 1)


def dfs(x):
    global res
    c = 1
    vis = set()
    for y, i in e[x]:
        vis.add(res[i])
    # print(x, vis)
    for y, i in e[x]:
        if res[i] > 0:
            continue
        while c in vis:
            c += 1
        # print(x, c)
        res[i] = c
        vis.add(c)
        dfs(y)


dfs(1)
print((max(res)))
for r in res:
    print(r)

- -sys.setrecursionlimit(10**7) +sys.setrecursionlimit(10**6) -    a, b = tuple(map(int, input().split())) -    e[a].append((b, i)) -    e[b].append((a, i)) +    u, v = list(map(int, input().split())) +    e[u].append((v, i)) +    e[v].append((u, i)) -vis = set() -    global vis -    viss = set() -    svis = set() -    t = 1 +    c = 1 +    vis = set() -        if i in vis: -            viss.add(res[i]) -    # print(x, viss) +        vis.add(res[i]) +    # print(x, vis) -        # print(x, y, t) -        while t in viss: -            t += 1 -        if i in vis: +        if res[i] > 0: -        # print(x, y, t) -        svis.add(y) -        vis.add(i) -        res[i] = t -        t += 1 +        while c in vis: +            c += 1 +        # print(x, c) +        res[i] = c +        vis.add(c) -    # print(res)