Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        colors = list(range(1,SIZE+1))
        if prev_color:
            colors.remove(prev_color)
        for w, i in edges[v]:
            if not color[i]:
                if colors:
                    color[i] = colors.pop(0)
                else:
                    SIZE += 1
                    color[i] = SIZE
                q.append((w,color[i]))
    print(SIZE)
    for n in range(N-1):
        print(color[n])

Fixed submission:
if __name__ == "__main__":
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        c = 1
        for w, i in edges[v]:
            if not color[i]:
                if c == prev_color:
                    c += 1
                color[i] = c
                c += 1
                q.append((w,color[i]))
        SIZE = max(SIZE, c-1)
    print(SIZE)
    for n in range(N-1):
        print(color[n])

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    from collections import deque
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        colors = list(range(1,SIZE+1))
        if prev_color:
            colors.remove(prev_color)
        for w, i in edges[v]:
            if not color[i]:
                if colors:
                    color[i] = colors.pop(0)
                else:
                    SIZE += 1
                    color[i] = SIZE
                q.append((w,color[i]))
    print(SIZE)
    for n in range(N-1):
        print(color[n])

Fixed submission:
if __name__ == "__main__":
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        c = 1
        for w, i in edges[v]:
            if not color[i]:
                if c == prev_color:
                    c += 1
                color[i] = c
                c += 1
                q.append((w,color[i]))
        SIZE = max(SIZE, c-1)
    print(SIZE)
    for n in range(N-1):
        print(color[n])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b,i))
    edges[b].append((a,i))

color = [None]*(N-1)
SIZE = 1
q = deque([(0,None)])
while q:
    v, prev_color = q.popleft()
    colors = list(range(1,SIZE+1))
    if prev_color:
        colors.remove(prev_color)
    for w, i in edges[v]:
        if not color[i]:
            if colors:
                color[i] = colors.pop(0)
            else:
                SIZE += 1
                color[i] = SIZE
            q.append((w,color[i]))
print(SIZE)
for n in range(N-1):
    print(color[n])

Fixed submission:
if __name__ == "__main__":
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        c = 1
        for w, i in edges[v]:
            if not color[i]:
                if c == prev_color:
                    c += 1
                color[i] = c
                c += 1
                q.append((w,color[i]))
        SIZE = max(SIZE, c-1)
    print(SIZE)
    for n in range(N-1):
        print(color[n])

Buggy python submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b,i))
    edges[b].append((a,i))

color = [None]*(N-1)
SIZE = 1
def dfs(i, prev):
    global SIZE
    colors = list(range(1, SIZE+1))
    if prev:
        colors.remove(prev)
    for j, n in edges[i]:
        if not color[n]:
            if not colors:
                SIZE += 1
                color[n] = SIZE
            else:
                color[n] = colors.pop()
            dfs(j, color[n])
dfs(0, None)
print(SIZE)
for n in range(N-1):
    print(color[n])

Fixed submission:
if __name__ == "__main__":
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        c = 1
        for w, i in edges[v]:
            if not color[i]:
                if c == prev_color:
                    c += 1
                color[i] = c
                c += 1
                q.append((w,color[i]))
        SIZE = max(SIZE, c-1)
    print(SIZE)
    for n in range(N-1):
        print(color[n])