import sys

sys.setrecursionlimit(10**9)

 

N = int(eval(input()))

edge = [[] for i in range(N)]

count = [0] * N

color = {}

egs = []

for i in range(N-1):

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

    a -= 1

    b -= 1

    count[a] += 1

    count[b] += 1

    edge[a].append(b)

    edge[b].append(a)

    egs.append(tuple(sorted([a, b])))

 

 

ans = max(count)

c = 1

 

 

 

def dfs(idx, pr):

    c = 1

    col = color[pr]

    for i in edge[idx]:

        if i in pr:

            continue

        if c == col:

            c+=1

        x, y = sorted([i, idx])

        color[(x, y)] = c

        dfs(i, (x, y))

        c+=1

 

color[(-1, -1)] = 0

dfs(0, (-1, -1))

print(ans)

for tpl in egs:

    print((color[tpl]))

 

 
import sys

from collections import deque, defaultdict

def input() : return sys.stdin.readline().strip()



def main():

    N = int(eval(input()))

    edges = [tuple(map(int, input().split())) for _ in range(N-1)]

    to = [[] for i in range(N)]



    for edge in edges:

        a, b = edge

        a -= 1

        b -= 1

        to[a].append(b)

        to[b].append(a)

    

    colors = defaultdict(int)

    def bfs():

        q = deque() # (index, parent color)

        q.append((0, 0))

        while len(q):

            now, par_col = q.popleft()

            color = 0

            for v in to[now]:

                x, y = sorted([v, now])

                if colors[(x, y)]:

                    continue

                else:

                    color += 1

                    if color == par_col:

                        color += 1



                    colors[(x, y)] = color

                    q.append((v, color))

    bfs()



    ans = max(colors.values())

    print(ans)

    

    for edge in edges:

        x, y = edge

        x -= 1

        y -= 1

        print((colors[(x, y)]))



                





        







if __name__ == "__main__":

    main()
import sys

sys.setrecursionlimit(10**9)
N = int(eval(input()))
edge = [[] for i in range(N)]
count = [0] * N
color = {}
egs = []
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    count[a] += 1
    count[b] += 1
    edge[a].append(b)
    edge[b].append(a)
    egs.append(tuple(sorted([a, b])))
ans = max(count)
c = 1


def dfs(idx, pr):
    c = 1
    col = color[pr]
    for i in edge[idx]:
        if i in pr:
            continue
        if c == col:
            c += 1
        x, y = sorted([i, idx])
        color[(x, y)] = c
        dfs(i, (x, y))
        c += 1


color[(-1, -1)] = 0
dfs(0, (-1, -1))
print(ans)
for tpl in egs:
    print((color[tpl]))

import sys
from collections import deque, defaultdict


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(eval(input()))
    edges = [tuple(map(int, input().split())) for _ in range(N - 1)]
    to = [[] for i in range(N)]
    for edge in edges:
        a, b = edge
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
    colors = defaultdict(int)

    def bfs():
        q = deque()  # (index, parent color)
        q.append((0, 0))
        while len(q):
            now, par_col = q.popleft()
            color = 0
            for v in to[now]:
                x, y = sorted([v, now])
                if colors[(x, y)]:
                    continue
                else:
                    color += 1
                    if color == par_col:
                        color += 1
                    colors[(x, y)] = color
                    q.append((v, color))

    bfs()
    ans = max(colors.values())
    print(ans)
    for edge in edges:
        x, y = edge
        x -= 1
        y -= 1
        print((colors[(x, y)]))


if __name__ == "__main__":
    main()

- -sys.setrecursionlimit(10**9) -N = int(eval(input())) -edge = [[] for i in range(N)] -count = [0] * N -color = {} -egs = [] -for i in range(N - 1): -    a, b = list(map(int, input().split())) -    a -= 1 -    b -= 1 -    count[a] += 1 -    count[b] += 1 -    edge[a].append(b) -    edge[b].append(a) -    egs.append(tuple(sorted([a, b]))) -ans = max(count) -c = 1 +from collections import deque, defaultdict -def dfs(idx, pr): -    c = 1 -    col = color[pr] -    for i in edge[idx]: -        if i in pr: -            continue -        if c == col: -            c += 1 -        x, y = sorted([i, idx]) -        color[(x, y)] = c -        dfs(i, (x, y)) -        c += 1 +def input(): +    return sys.stdin.readline().strip() -color[(-1, -1)] = 0 -dfs(0, (-1, -1)) -print(ans) -for tpl in egs: -    print((color[tpl])) +def main(): +    N = int(eval(input())) +    edges = [tuple(map(int, input().split())) for _ in range(N - 1)] +    to = [[] for i in range(N)] +    for edge in edges: +        a, b = edge +        a -= 1 +        b -= 1 +        to[a].append(b) +        to[b].append(a) +    colors = defaultdict(int) + +    def bfs(): +        q = deque()  # (index, parent color) +        q.append((0, 0)) +        while len(q): +            now, par_col = q.popleft() +            color = 0 +            for v in to[now]: +                x, y = sorted([v, now]) +                if colors[(x, y)]: +                    continue +                else: +                    color += 1 +                    if color == par_col: +                        color += 1 +                    colors[(x, y)] = color +                    q.append((v, color)) + +    bfs() +    ans = max(colors.values()) +    print(ans) +    for edge in edges: +        x, y = edge +        x -= 1 +        y -= 1 +        print((colors[(x, y)])) + + +if __name__ == "__main__": +    main()