N = int(eval(input()))

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



for i in range(N - 1):

    fr, to = [int(a) - 1 for a in input().split()]

    edges[fr].append((i, to))

    edges[to].append((i, fr))



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

st = [(0, -1)]

while st:

    now, pr = st.pop()



    C = []

    D = set()

    for i, _ in edges[now]:

        D.add(ans[i])

    for i in range(len(edges[now]) + 1)[::-1]:

        if i in D:

            continue

        C.append(i)



    for i, to in edges[now]:

        if to == pr:

            continue

        ans[i] = C.pop()

        st.append((to, now))



print((max(ans) + 1))

for a in ans:

    print((a + 1))

N = int(input())

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



for i in range(N - 1):

    fr, to = map(lambda a: int(a) - 1, input().split())

    edges[fr].append((i, to))

    edges[to].append((i, fr))



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

A = [set() for _ in range(N)]



st = [0]

while st:

    now = st.pop()

    s = 1

    for i, to in edges[now]:

        if ans[i] != -1:

            continue

        while s in A[now]:

            s += 1

        ans[i] = s

        A[to].add(s)

        A[now].add(s)

        st.append(to)



print(max(ans))

print(*ans, sep="\n")

N = int(eval(input()))
edges = [[] for _ in range(N)]
for i in range(N - 1):
    fr, to = [int(a) - 1 for a in input().split()]
    edges[fr].append((i, to))
    edges[to].append((i, fr))
ans = [-1] * (N - 1)
st = [(0, -1)]
while st:
    now, pr = st.pop()
    C = []
    D = set()
    for i, _ in edges[now]:
        D.add(ans[i])
    for i in range(len(edges[now]) + 1)[::-1]:
        if i in D:
            continue
        C.append(i)
    for i, to in edges[now]:
        if to == pr:
            continue
        ans[i] = C.pop()
        st.append((to, now))
print((max(ans) + 1))
for a in ans:
    print((a + 1))

N = int(input())
edges = [[] for _ in range(N)]
for i in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append((i, to))
    edges[to].append((i, fr))
ans = [-1] * (N - 1)
A = [set() for _ in range(N)]
st = [0]
while st:
    now = st.pop()
    s = 1
    for i, to in edges[now]:
        if ans[i] != -1:
            continue
        while s in A[now]:
            s += 1
        ans[i] = s
        A[to].add(s)
        A[now].add(s)
        st.append(to)
print(max(ans))
print(*ans, sep="\n")

-N = int(eval(input())) +N = int(input()) -    fr, to = [int(a) - 1 for a in input().split()] +    fr, to = map(lambda a: int(a) - 1, input().split()) -st = [(0, -1)] +A = [set() for _ in range(N)] +st = [0] -    now, pr = st.pop() -    C = [] -    D = set() -    for i, _ in edges[now]: -        D.add(ans[i]) -    for i in range(len(edges[now]) + 1)[::-1]: -        if i in D: +    now = st.pop() +    s = 1 +    for i, to in edges[now]: +        if ans[i] != -1: -        C.append(i) -    for i, to in edges[now]: -        if to == pr: -            continue -        ans[i] = C.pop() -        st.append((to, now)) -print((max(ans) + 1)) -for a in ans: -    print((a + 1)) +        while s in A[now]: +            s += 1 +        ans[i] = s +        A[to].add(s) +        A[now].add(s) +        st.append(to) +print(max(ans)) +print(*ans, sep="\n")