Problem p03044 (python)

Fixed submission:
N = int(input())
color = [ [] for i in range(N)]

def updateColor( color, i, from_i, c):
    if len(color[i]) == 1 and color[i][0][0] == from_i:
        color[i] = c
    else:
        for l in color[i]:
            if l[0] != from_i:
                if l[1] == 'Same':
                    updateColor( color, l[0], i, c)
                else:
                    updateColor( color, l[0], i, 1-c)
        color[i] = c
                    

for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    if i == 0:
        if w%2 == 0:
            color[u] = color[v] = 0
        else:
            color[u] = 0
            color[v] = 1
    else:
        if color[u] in (0,1):
            if w%2 == 0:
                temp = color[u]
            else:
                temp = 1-color[u]

            for l in color[v]:
                if l[1] == "Same":
                    updateColor( color, l[0], v, temp )
                else:
                    updateColor( color, l[0], v, 1-temp )
            color[v] = temp

        elif color[v] in (0,1):
            if w%2 == 0:
                temp = color[v]
            else:
                temp = 1-color[v]
                
            for l in color[u]:
                if l[1] == "Same":
                    updateColor( color, l[0], u, temp )
                else:
                    updateColor( color, l[0], u, 1-temp )
            color[u] = temp

        else:
            if w%2 == 0:
                color[u].append([v, "Same"])
                color[v].append([u, "Same"])
            else:
                color[u].append([v, "Diff"])
                color[v].append([u, "Diff"])
                    
for c in color:
    print(c)

Buggy submission (verdict: Runtime Error):
N = int(input())
color = [ [] for i in range(N)]

def updateColor( color, i, from_i, c):
    if len(color[i]) == 1 and color[i][0][0] == from_i:
        color[i] = c
    else:
        for l in color[i]:
            if l[1] == 'Same':
                updateColor( color, l[0], c)
            else:
                updateColor( color, l[0], 1-c)


for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    if i == 0:
        if w%2 == 0:
            color[u] = color[v] = 0
        else:
            color[u] = 0
            color[v] = 1
    else:
        if color[u] in (0,1):
            if w%2 == 0:
                temp = color[u]
            else:
                temp = 1-color[u]

            for l in color[v]:
                if l[1] == "Same":
                    updateColor( color, l[0], temp )
                else:
                    updateColor( color, l[0], 1-temp )
            color[v] = temp

        elif color[v] in (0,1):
            if w%2 == 0:
                temp = color[v]
            else:
                temp = 1-color[v]
                
            for l in color[u]:
                if l[1] == "Same":
                    updateColor( color, l[0], temp )
                else:
                    updateColor( color, l[0], 1-temp )
            color[u] = temp

        else:
            if w%2 == 0:
                color[u].append([v, "Same"])
                color[v].append([u, "Same"])
            else:
                color[u].append([v, "Diff"])
                color[v].append([u, "Diff"])

for c in color:
    print(c)