Problem p03668 (python)

Fixed submission:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    N, A, B, C, D = LI()
    for i in range(N-1):
        low = A + i*C - (N-1-i)*D
        up = A + i*D - (N-1-i)*C
        if low<=B<=up:
            print("YES")
            return
    print("NO")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        x, y = LI()
        x -= 1; y -= 1
        V[x].append(y)
        V[y].append(x)
    def dfs(s,p):
        grundy = 0
        judge = len(V[s])
        if p==-1:
            judge += 1
        if judge==1:
            return grundy
        if judge==2:
            for v in V[s]:
                if v == p:
                    continue
                cur = dfs(v, s)
                grundy = cur+1
            return grundy
        for v in V[s]:
            if v==p:
                continue
            cur = dfs(v,s)+1
            #print(cur)
            grundy ^= cur

        return grundy
    ans = "Alice"
    if dfs(0,-1)==0:
        ans = "Bob"
    print(ans)
    return

def examE():
    N, H = LI()
    A = [LI()for _ in range(N)]


    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)


if __name__ == '__main__':
    examD()

"""

"""

Buggy submission (verdict: Runtime Error):
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    N, A, B, C, D = LI()
    for i in range(N-1):
        low = A + i*C - (N-1-i)*D
        up = A + i*D - (N-1-i)*C
        if low<=B<=up:
            print("YES")
            return
    print("NO")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        x, y = LI()
        x -= 1; y -= 1
        V[x].append(y)
        V[y].append(x)
    def dfs(s,p):
        grundy = 0
        judge = len(V[s])
        if p==-1:
            judge += 1
        if judge==1:
            return grundy
        if judge==2:
            for v in V[s]:
                if v == p:
                    continue
                cur = dfs(v, s)
                grundy = cur+1
            return grundy
        for v in V[s]:
            if v==p:
                continue
            cur = dfs(v,s)
            grundy ^= cur

        return grundy
    ans = "Alice"
    if dfs(0,-1)==0:
        ans = "Bob"
    print(ans)
    return

def examE():
    N, H = LI()
    A = [LI()for _ in range(N)]


    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""