from collections import Counter, defaultdict

from queue import Queue

G = defaultdict(list)



C = Counter()

N = int(eval(input()))

ans = {}

o = []

for i in range(N-1):

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

    C[a] += 1

    C[b] += 1

    G[a].append(b)

    G[b].append(a)

    ans[(a, b)] = 0

    o.append((a,b))



cs = [0] * (N+1)

def bfs(v):

    ret = 0

    visited = set()

    q = Queue()

    visited.add(v)

    q.put(v)

    while not q.empty():

        v = q.get()

        counter = 1

        for c in G[v]:

            if not c in visited:

                visited.add(c)

                if counter == cs[v]:

                    counter += 1

                cs[c] = ans[(c,v)] = ans[(v,c)] = counter

                counter += 1

                q.put(c)



bfs(1)

print((C.most_common(1)[0][1]))

for a,b in o:

    print((ans[(a,b)]))
from collections import Counter, defaultdict

from sys import getrecursionlimit,setrecursionlimit

setrecursionlimit(100*getrecursionlimit())

G = defaultdict(list)

C = Counter()

N = int(eval(input()))

ans = {}

o = []

for i in range(N-1):

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

    C[a] += 1

    C[b] += 1

    G[a].append(b)

    G[b].append(a)

    ans[(a, b)] = 0

    o.append((a,b))



a = C.most_common(1)[0][0]

b = C.most_common(1)[0][1]



visited = [False] * (N+1)

def dfs(v, p):

    visited[v] = True

    counter = 1

    for c in G[v]:

        if not visited[c]:

            if p != 0 and counter == ans[(v, p)]:

                counter += 1

            ans[(v, c)] = ans[(c, v)] = counter

            counter += 1

            dfs(c, v)



dfs(a, 0)



print(b)

for a,b in o:

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

from collections import Counter, defaultdict
from queue import Queue

G = defaultdict(list)
C = Counter()
N = int(eval(input()))
ans = {}
o = []
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    C[a] += 1
    C[b] += 1
    G[a].append(b)
    G[b].append(a)
    ans[(a, b)] = 0
    o.append((a, b))
cs = [0] * (N + 1)


def bfs(v):
    ret = 0
    visited = set()
    q = Queue()
    visited.add(v)
    q.put(v)
    while not q.empty():
        v = q.get()
        counter = 1
        for c in G[v]:
            if not c in visited:
                visited.add(c)
                if counter == cs[v]:
                    counter += 1
                cs[c] = ans[(c, v)] = ans[(v, c)] = counter
                counter += 1
                q.put(c)


bfs(1)
print((C.most_common(1)[0][1]))
for a, b in o:
    print((ans[(a, b)]))

from collections import Counter, defaultdict
from sys import getrecursionlimit, setrecursionlimit

setrecursionlimit(100 * getrecursionlimit())
G = defaultdict(list)
C = Counter()
N = int(eval(input()))
ans = {}
o = []
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    C[a] += 1
    C[b] += 1
    G[a].append(b)
    G[b].append(a)
    ans[(a, b)] = 0
    o.append((a, b))
a = C.most_common(1)[0][0]
b = C.most_common(1)[0][1]
visited = [False] * (N + 1)


def dfs(v, p):
    visited[v] = True
    counter = 1
    for c in G[v]:
        if not visited[c]:
            if p != 0 and counter == ans[(v, p)]:
                counter += 1
            ans[(v, c)] = ans[(c, v)] = counter
            counter += 1
            dfs(c, v)


dfs(a, 0)
print(b)
for a, b in o:
    print((ans[(a, b)]))

-from queue import Queue +from sys import getrecursionlimit, setrecursionlimit +setrecursionlimit(100 * getrecursionlimit()) -cs = [0] * (N + 1) +a = C.most_common(1)[0][0] +b = C.most_common(1)[0][1] +visited = [False] * (N + 1) -def bfs(v): -    ret = 0 -    visited = set() -    q = Queue() -    visited.add(v) -    q.put(v) -    while not q.empty(): -        v = q.get() -        counter = 1 -        for c in G[v]: -            if not c in visited: -                visited.add(c) -                if counter == cs[v]: -                    counter += 1 -                cs[c] = ans[(c, v)] = ans[(v, c)] = counter +def dfs(v, p): +    visited[v] = True +    counter = 1 +    for c in G[v]: +        if not visited[c]: +            if p != 0 and counter == ans[(v, p)]: -                q.put(c) +            ans[(v, c)] = ans[(c, v)] = counter +            counter += 1 +            dfs(c, v) -bfs(1) -print((C.most_common(1)[0][1])) +dfs(a, 0) +print(b)