import sys

sys.setrecursionlimit(1000000)

 

n = int(eval(input()))

g = [[] for _ in range(n)]

for i in range(n-1):

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

  a, b = a-1, b-1

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

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

  

ans = [0]*(n-1)

  

def dfs(v, c=-1, p=-1):

  k = 1

  for u, ei in g[v]:

    if u == p:

      continue

    if k == c:

      k += 1

    ans[ei] = k

    k += 1

    dfs(u, ans[ei], v)

 

dfs(0)

print((max(ans)))

for i in range(n-1):

  print((ans[i]))
import sys

input = sys.stdin.readline



n = int(eval(input()))

g = [[] for _ in range(n)]

e = []

for i in range(n-1):

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

    a, b = a-1, b-1

    g[a].append(b)

    g[b].append(a)

    e.append((a, b))



# topological順序の計算

s = []

s.append(0)

parent = [-1]*n

order = []

while s:

    x = s.pop()

    order.append(x)

    for nx in g[x]:

        if nx == parent[x]:

            continue

        parent[nx] = x

        s.append(nx)



color = [0]*n

for v in order:

    ng = color[v]

    c = 1

    for u in g[v]:

        if u == parent[v]:

            continue

        if c == ng:

            c += 1

        color[u] = c

        c += 1



ans = []

for a, b in e:

    if parent[a] == b:

        ans.append(color[a])

    else:

        ans.append(color[b])



print((len(set(ans))))

print(('\n'.join(map(str,ans))))
import sys

sys.setrecursionlimit(1000000)
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    g[a].append([b, i])
    g[b].append([a, i])
ans = [0] * (n - 1)


def dfs(v, c=-1, p=-1):
    k = 1
    for u, ei in g[v]:
        if u == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k
        k += 1
        dfs(u, ans[ei], v)


dfs(0)
print((max(ans)))
for i in range(n - 1):
    print((ans[i]))

import sys

input = sys.stdin.readline
n = int(eval(input()))
g = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    g[a].append(b)
    g[b].append(a)
    e.append((a, b))
# topological順序の計算
s = []
s.append(0)
parent = [-1] * n
order = []
while s:
    x = s.pop()
    order.append(x)
    for nx in g[x]:
        if nx == parent[x]:
            continue
        parent[nx] = x
        s.append(nx)
color = [0] * n
for v in order:
    ng = color[v]
    c = 1
    for u in g[v]:
        if u == parent[v]:
            continue
        if c == ng:
            c += 1
        color[u] = c
        c += 1
ans = []
for a, b in e:
    if parent[a] == b:
        ans.append(color[a])
    else:
        ans.append(color[b])
print((len(set(ans))))
print(("\n".join(map(str, ans))))

-sys.setrecursionlimit(1000000) +input = sys.stdin.readline +e = [] -    g[a].append([b, i]) -    g[b].append([a, i]) -ans = [0] * (n - 1) - - -def dfs(v, c=-1, p=-1): -    k = 1 -    for u, ei in g[v]: -        if u == p: +    g[a].append(b) +    g[b].append(a) +    e.append((a, b)) +# topological順序の計算 +s = [] +s.append(0) +parent = [-1] * n +order = [] +while s: +    x = s.pop() +    order.append(x) +    for nx in g[x]: +        if nx == parent[x]: -        if k == c: -            k += 1 -        ans[ei] = k -        k += 1 -        dfs(u, ans[ei], v) - - -dfs(0) -print((max(ans))) -for i in range(n - 1): -    print((ans[i])) +        parent[nx] = x +        s.append(nx) +color = [0] * n +for v in order: +    ng = color[v] +    c = 1 +    for u in g[v]: +        if u == parent[v]: +            continue +        if c == ng: +            c += 1 +        color[u] = c +        c += 1 +ans = [] +for a, b in e: +    if parent[a] == b: +        ans.append(color[a]) +    else: +        ans.append(color[b]) +print((len(set(ans)))) +print(("\n".join(map(str, ans))))