Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, links, edge, pc):
    c = 1
    if pc == c:
        c += 1

    for n, i in links:
        if n < 0 or i < 0:
            exit()
        if n >= len(nodes) or i >= len(edge):
            exit()

        if edge[i] != 0:
            continue
        edge[i] = c
        fill(nodes, nodes[n], edge, c)

        c += 1
        if pc == c:
            c += 1

    
fill(nodes, nodes[max_i], edge, 0)

print(max_l)
for e in edge:
    print(e)



Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, links, edge, pc):
    c = 1
    if pc == c:
        c += 1

    next_fills = []
    for n, i in links:
        if edge[i] != 0:
            continue
        edge[i] = c
        fill(nodes, nodes[n], edge, c)

        c += 1
        if pc == c:
            c += 1

    
fill(nodes, nodes[max_i], edge, 0)

print(max_l)
for e in edge:
    print(e)

Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []

for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) for v in input().split(' ')]
    a -= 1
    b -= 1
    nodes[a].append((b, i))
    nodes[b].append((a, i))

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, links, edge, pc):
    c = 1
    while pc & (1 << c) != 0:
        c += 1

    next_fills = []
    for n, i in links:
        if edge[i] != 0:
            pc |= (1 << edge[i])
            continue
        edge[i] = c
        next_fills.append((n, c))

        c += 1
        while pc & (1 << c) != 0:
            c += 1

    for n, c in next_fills:
        fill(nodes, nodes[n], e, (c << 1))
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)

print(max_l)
for i in e:
    print(i)



Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []

for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) for v in input().split(' ')]
    a -= 1
    b -= 1
    nodes[a].append((b, i))
    nodes[b].append((a, i))


max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, links, e, pc):
    c = 1
    if c == pc:
        c += 1

    next_fills = []
    for n, i in links:
        if e[i] != 0:
            continue
        e[i] = c
        next_fills.append((n, c))

        c += 1
        if c == pc:
            c += 1

    for n, c in next_fills:
        fill(nodes, nodes[n], e, c)
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)

print(max_l)
for i in e:
    print(i)

Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []
edges = []

for i in range(N):
    nodes.append([])


for i in range(N-1):
    a, b = [int(v) for v in input().split()]
    a -= 1
    b -= 1

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

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l <= l:
        max_l = l
        max_i = i


def fill(nodes, links, e, pc):
    c = 1
    if c == pc:
        c += 1
    for n, i in links:
        if e[i] != 0:
            continue
        e[i] = c
        fill(nodes, nodes[n], e, c)

        c += 1
        if c == pc:
            c += 1
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)

print(max_l)
for i in e:
    print(i)



Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []
edges = []

for i in range(N):
    nodes.append([])


for i in range(N-1):
    a, b = [int(v) for v in input().split()]
    a -= 1
    b -= 1

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

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i


def fill(nodes, links, e, pc):
    c = 1
    if c == pc:
        c += 1
    for n, i in links:
        if e[i] != 0:
            continue
        e[i] = c
        fill(nodes, nodes[n], e, c)

        c += 1
        if c == pc:
            c += 1
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)

print(max_l)
for i in e:
    print(i)

Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []
edges = []

for i in range(N):
    nodes.append([])


for i in range(N-1):
    a, b = [int(v) for v in input().split()]
    a -= 1
    b -= 1

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

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i


def fill(nodes, links, e, pc):
    c = 1
    if c == p:
        c += 1
    for n, i in links:
        if e[i] != 0:
            continue
        e[i] = c
        fill(nodes, nodes[n], e, c)

        c += 1
        if c == pc:
            c += 1
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)

print(max_l)
for i in e:
    print(i)

Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)

Buggy python submission (verdict: Runtime Error):
N = int(input())

nodes = []
edges = []

for i in range(N):
    nodes.append([])


for i in range(N-1):
    a, b = [int(v) for v in input().split()]
    a -= 1
    b -= 1

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

max_l = 0
max_i = 0
for i in range(N):
    l = len(nodes[i])
    if max_l < l:
        max_l = l
        max_i = i


def fill(nodes, links, e, p):
    c = 1
    if c == p:
        c += 1
    for n, i in links:
        if e[i] != 0:
            continue
        e[i] = c
        fill(nodes, nodes[n], e, c)

        c += 1
        if c == p:
            c += 1
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)
print(max_l)

for i in e:
    print(i)

Fixed submission:
N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)