Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD) 



Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

T = defaultdict(list)
for i in range(N-1):
    x,y = map(int, input().split())
    T[x] += [y]
    T[y] += [x]

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD) 



Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())

from collections import defaultdict

MOD = 10**9 + 7
T = defaultdict(list)
for i in range(N-1):
    x,y = map(int, input().split())
    T[x] += [y]
    T[y] += [x]

DP = [[0] * (N+1) for _ in range(2)]

def dfs(n,oya):

    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD) 



Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())

from collections import defaultdict

MOD = 10**9 + 7
T = defaultdict(list)
R = defaultdict(list)
visited = [-1]*(N+1)
for i in range(N-1):
    x,y = map(int, input().split())
    # x,y = min(x,y), max(x,y)
    T[x] += [y]
    T[y] += [x]

# DP = defaultdict(lambda : 0 )
DP = [[0] * (N+1) for _ in range(2)]

root = 1
visited[root] = 1
node = root
from collections import deque
q = deque()
q.append(node)

# while q:
#     node = q.popleft()
#     # print("node: ,", node)
#     if all(visited[child]!=-1 for child in T[node]):
#         continue
#     for chnode in T[node]:
#         if visited[chnode] == -1:
#             R[node] += [chnode]
#             visited[chnode] = 1
#             q.append(chnode)


def dfs(c,n,oya):
    # if len(T[n]) == 0:
    #     DP[0][n] = 1
    #     DP[1][n] = 1
    #     return 1

    if c == 0:
        black = 1
        for child_n in T[n]:
            if child_n == oya:
                continue
            black *= dfs(1, child_n, n) % MOD
        DP[0][n] = black % MOD
        return black % MOD
    else:
        white = 1
        for child_n in T[n]:
            if child_n == oya:
                continue
            white *= dfs(0, child_n, n) + dfs(1, child_n,n) % MOD
        DP[1][n] = white % MOD
        return white % MOD

print( (dfs(0, 1, None) + dfs(1,1, None)) % MOD) 



Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
# T = [ [int(j) for j in input().split()] for _ in range(N-1)]

from collections import defaultdict

MOD = 10**9 + 7
T = defaultdict(list)
R = defaultdict(list)
visited = [-1]*(N+1)
for i in range(N-1):
    x,y = map(int, input().split())
    # x,y = min(x,y), max(x,y)
    T[x] += [y]
    T[y] += [x]

# DP = defaultdict(lambda : 0 )
DP = [[0] * (N+1) for _ in range(2)]
# visited = [False] * (N+1)

root = 1
visited[root] = 1
node = root
from collections import deque
q = deque()
q.append(node)

while q:
    node = q.popleft()
    # print("node: ,", node)
    if all(visited[child]!=-1 for child in T[node]):
        continue
    for chnode in T[node]:
        if visited[chnode] == -1:
            R[node] += [chnode]
            visited[chnode] = 1
            q.append(chnode)
    
# 0 for black
# 1 for white
# print(R)

def dfs(c,n):
    if len(R[n]) == 0:
        DP[0][n] = 1
        DP[1][n] = 1
        return 1

    if c == 0:
        black = 1
        for child_n in R[n]:
            black *= dfs(1, child_n) % MOD
        DP[0][n] = black % MOD
        return black % MOD
    else:
        white = 1
        for child_n in R[n]:
            white *= dfs(0, child_n) + dfs(1, child_n) % MOD
        DP[1][n] = white % MOD
        return white % MOD

print( (dfs(0, 1) + dfs(1,1)) % MOD) 




Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD)