Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

mod = 10**9+7
n = int(input())
edges = [[] for i in range(n)]
for i in range(n-1):
    x,y = map(int, input().split())
    x,y = x-1, y-1
    edges[x].append(y)
    edges[y].append(x)

def rec(cur, prev=None):
    white = 1
    black = 1
    for to in edges[cur]:
        if to == prev:
            continue
        w,b = rec(to, cur)
        white *= (w+b)
        white %= mod
        black *= w
        black %= mod
    return white, black

w, b = rec(0)
print((w+b)%mod)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def main():
    input = sys.stdin.readline

    mod = 10**9+7
    n = int(input())
    edges = [[] for i in range(n)]
    for i in range(n-1):
        x,y = map(int, input().split())
        x,y = x-1, y-1
        edges[x].append(y)
        edges[y].append(x)

    def rec(cur, prev=None):
        white = 1
        black = 1
        for to in edges[cur]:
            if to == prev:
                continue
            w,b = rec(to, cur)
            white *= (w+b)
            white %= mod
            black *= w
            black %= mod
        return white, black

    w, b = rec(0)
    print((w+b)%mod)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7
n = int(input())
edges = [[] for i in range(n)]
for i in range(n-1):
    x,y = map(int, input().split())
    x,y = x-1, y-1
    edges[x].append(y)
    edges[y].append(x)

memo = [[-1]*2 for i in range(n)]
def rec(cur, prev=None):
    white = 1
    black = 1
    for to in edges[cur]:
        if to == prev:
            continue
        w,b = rec(to, cur)
        white *= (w+b)
        white %= mod
        black *= w
        black %= mod
    return white, black

w, b = rec(0)
print((w+b)%mod)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def main():
    input = sys.stdin.readline

    mod = 10**9+7
    n = int(input())
    edges = [[] for i in range(n)]
    for i in range(n-1):
        x,y = map(int, input().split())
        x,y = x-1, y-1
        edges[x].append(y)
        edges[y].append(x)

    def rec(cur, prev=None):
        white = 1
        black = 1
        for to in edges[cur]:
            if to == prev:
                continue
            w,b = rec(to, cur)
            white *= (w+b)
            white %= mod
            black *= w
            black %= mod
        return white, black

    w, b = rec(0)
    print((w+b)%mod)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque, defaultdict

mod = 10**9+7

n = int(input())
d = defaultdict(list)
for i in range(n-1):
    x,y = map(lambda x:int(x)-1, input().split())
    d[x].append(y)
    d[y].append(x)

if n == 1:
    print(2)
    exit()

dp = [[0]*2 for i in range(n)]

q = deque()
for i in range(n):
    if len(d[i]) == 1:
        q.append(i)

visited = set()

while True:
    i = q.popleft()
    if i in visited:
        continue

    white = 1
    other = 1
    cnt = 0
    next_i = -1
    for j in d[i]:
        if j in visited:
            white = (white*dp[j][0]) % mod
            other = (other*sum(dp[j])) % mod
        else:
            cnt += 1
            next_i = j
    if cnt > 1:
        q.append(i)
        continue
    dp[i][0] = other
    dp[i][1] = white
    visited.add(i)
    if cnt == 0:
        print(sum(dp[i])%mod)
        exit()
    q.append(next_i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def main():
    input = sys.stdin.readline

    mod = 10**9+7
    n = int(input())
    edges = [[] for i in range(n)]
    for i in range(n-1):
        x,y = map(int, input().split())
        x,y = x-1, y-1
        edges[x].append(y)
        edges[y].append(x)

    def rec(cur, prev=None):
        white = 1
        black = 1
        for to in edges[cur]:
            if to == prev:
                continue
            w,b = rec(to, cur)
            white *= (w+b)
            white %= mod
            black *= w
            black %= mod
        return white, black

    w, b = rec(0)
    print((w+b)%mod)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque, defaultdict

mod = 10**9+7

n = int(input())
d = defaultdict(list)
for i in range(n-1):
    x,y = map(lambda x:int(x)-1, input().split())
    d[x].append(y)
    d[y].append(x)

if n == 1:
    print(2)
    exit()

dp = [[0]*2 for i in range(n)]

q = deque()
for i in range(n):
    if len(d[i]) == 1:
        q.append(i)

visited = set()

while True:
    i = q.popleft()
    if i in visited:
        continue

    white = 1
    other = 1
    cnt = 0
    next_i = -1
    for j in d[i]:
        if j in visited:
            white = (white*dp[j][0]) % mod
            other = (other*sum(dp[j])) % mod
        else:
            cnt += 1
            next_i = j
    if cnt > 1:
        q.append(i)
        continue
    dp[i][0] = other
    dp[i][1] = white
    visited.add(i)
    if cnt == 0:
        print(sum(dp[i])%mod)
        exit()
    q.append(next_i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def main():
    input = sys.stdin.readline

    mod = 10**9+7
    n = int(input())
    edges = [[] for i in range(n)]
    for i in range(n-1):
        x,y = map(int, input().split())
        x,y = x-1, y-1
        edges[x].append(y)
        edges[y].append(x)

    def rec(cur, prev=None):
        white = 1
        black = 1
        for to in edges[cur]:
            if to == prev:
                continue
            w,b = rec(to, cur)
            white *= (w+b)
            white %= mod
            black *= w
            black %= mod
        return white, black

    w, b = rec(0)
    print((w+b)%mod)

if __name__ == "__main__":
    main()