import sys

input = sys.stdin.readline

from collections import deque, defaultdict



def bfs():

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

    visited = [False]*N

    visited[0] = True

    

    while q:

        v, c = q.popleft()

        now = 1

        

        for nv in G[v]:

            if not visited[nv]:

                if now==c:

                    now += 1

                    

                k = 10**6*min(v, nv)+max(v, nv)

                ans[k] = now

                q.append((nv, now))

                visited[nv] = True

                now += 1



N = int(eval(input()))

edges = []

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



for _ in range(N-1):

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

    a -= 1

    b -= 1

    edges.append((a, b))

    G[a].append(b)

    G[b].append(a)



ans = defaultdict(int)

bfs()

K = max(list(ans.values()))



print(K)



for a, b in edges:

    print((ans[10**6*a+b]))

import sys

input = sys.stdin.readline

from collections import *



def bfs():

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

    visited = [False]*N

    visited[0] = True

    ans = [-1]*(N-1)



    while q:

        v, prev = q.popleft()

        now = 0



        for nv in G[v]:

            if not visited[nv]:

                if now==prev:

                    now += 1



                visited[nv] = True

                ans[idx[(min(v, nv), max(v, nv))]] = now

                q.append((nv, now))

                now += 1



    return ans



N = int(eval(input()))

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

idx = defaultdict(int)



for i in range(N-1):

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

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

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

    idx[(min(a-1, b-1), max(a-1, b-1))] = i



ans = bfs()

print((max(ans)+1))



for ans_i in ans:

    print((ans_i+1))
import sys

input = sys.stdin.readline
from collections import deque, defaultdict


def bfs():
    q = deque([(0, 0)])
    visited = [False] * N
    visited[0] = True
    while q:
        v, c = q.popleft()
        now = 1
        for nv in G[v]:
            if not visited[nv]:
                if now == c:
                    now += 1
                k = 10**6 * min(v, nv) + max(v, nv)
                ans[k] = now
                q.append((nv, now))
                visited[nv] = True
                now += 1


N = int(eval(input()))
edges = []
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edges.append((a, b))
    G[a].append(b)
    G[b].append(a)
ans = defaultdict(int)
bfs()
K = max(list(ans.values()))
print(K)
for a, b in edges:
    print((ans[10**6 * a + b]))

import sys

input = sys.stdin.readline
from collections import *


def bfs():
    q = deque([(0, -1)])
    visited = [False] * N
    visited[0] = True
    ans = [-1] * (N - 1)
    while q:
        v, prev = q.popleft()
        now = 0
        for nv in G[v]:
            if not visited[nv]:
                if now == prev:
                    now += 1
                visited[nv] = True
                ans[idx[(min(v, nv), max(v, nv))]] = now
                q.append((nv, now))
                now += 1
    return ans


N = int(eval(input()))
G = [[] for _ in range(N)]
idx = defaultdict(int)
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
    idx[(min(a - 1, b - 1), max(a - 1, b - 1))] = i
ans = bfs()
print((max(ans) + 1))
for ans_i in ans:
    print((ans_i + 1))

-from collections import deque, defaultdict +from collections import * -    q = deque([(0, 0)]) +    q = deque([(0, -1)]) +    ans = [-1] * (N - 1) -        v, c = q.popleft() -        now = 1 +        v, prev = q.popleft() +        now = 0 -                if now == c: +                if now == prev: -                k = 10**6 * min(v, nv) + max(v, nv) -                ans[k] = now +                visited[nv] = True +                ans[idx[(min(v, nv), max(v, nv))]] = now -                visited[nv] = True +    return ans -edges = [] -for _ in range(N - 1): +idx = defaultdict(int) +for i in range(N - 1): -    a -= 1 -    b -= 1 -    edges.append((a, b)) -    G[a].append(b) -    G[b].append(a) -ans = defaultdict(int) -bfs() -K = max(list(ans.values())) -print(K) -for a, b in edges: -    print((ans[10**6 * a + b])) +    G[a - 1].append(b - 1) +    G[b - 1].append(a - 1) +    idx[(min(a - 1, b - 1), max(a - 1, b - 1))] = i +ans = bfs() +print((max(ans) + 1)) +for ans_i in ans: +    print((ans_i + 1))