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

def main():
  N = int(input())
  XY = [tuple(map(int,input().split())) for _ in range(N-1)]
  MOD =10**9+7
  
  E = [[] for _ in range(N)]
  for x,y in XY:
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
  
  def dfs(v,s):
    b = 1
    w = 1
    for u in E[v]:
      if u != s:
        b0,w0 = dfs(u,v)
        b *= w0
        w *= (b0+w0)
    #b %= MOD
    #w %= MOD
    return b,w

  b,w = dfs(0,-1)
  print((b+w) % MOD)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
  N = int(input())
  XY = [tuple(map(int,input().split())) for _ in range(N-1)]
  MOD =10**9+7
  
  E = [[] for _ in range(N)]
  for x,y in XY:
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
  
  def dfs(v,s):
    b = 1
    w = 1
    for u in E[v]:
      if u != s:
        b0,w0 = dfs(u,v)
        b *= w0
        w *= (b0+w0)
    #b %= MOD
    #w %= MOD
    return b,w

  b,w = dfs(0,-1)
  print((b+w) % MOD)

if __name__ == '__main__':
    main()

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

def main():
  N = int(input())
  XY = [tuple(map(int,input().split())) for _ in range(N-1)]
  MOD =10**9+7
  
  E = [[] for _ in range(N)]
  for x,y in XY:
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
  
  # dp[v][c]:根がvである部分木において、vを色cで塗ったときの塗り方のパターン
  # vの子をu1,u2...unとすると、vが白ならuxは白でも黒でもいい。
  # vが黒ならuxは白でないといけない。
  # uxを根とする部分木の塗り方パターン数を掛け合わせたものが、
  # vを根とする部分木の塗り方のパターン数になる。
  dp = [[0 for _ in range(2)] for _ in range(N)]
  def dfs(v,c,s):
    dp[v][c] = 1
    for u in E[v]:
      if u != s:
        if c == 0: #vが白の場合
          dp[v][c] *= (dfs(u,0,v)+dfs(u,1,v))
        else: #vが黒の場合
          dp[v][c] *= dfs(u,0,v)
    #dp[v][c] %= MOD
    return dp[v][c]

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

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
  N = int(input())
  XY = [tuple(map(int,input().split())) for _ in range(N-1)]
  MOD =10**9+7
  
  E = [[] for _ in range(N)]
  for x,y in XY:
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
  
  def dfs(v,s):
    b = 1
    w = 1
    for u in E[v]:
      if u != s:
        b0,w0 = dfs(u,v)
        b *= w0
        w *= (b0+w0)
    #b %= MOD
    #w %= MOD
    return b,w

  b,w = dfs(0,-1)
  print((b+w) % MOD)

if __name__ == '__main__':
    main()

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

def main():
  N = int(input())
  XY = [tuple(map(int,input().split())) for _ in range(N-1)]
  MOD =10**9+7
  
  E = [[] for _ in range(N)]
  for x,y in XY:
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
  
  # dp[v][c]:根がvである部分木において、vを色cで塗ったときの塗り方のパターン
  # vの子をu1,u2...unとすると、vが白ならuxは白でも黒でもいい。
  # vが黒ならuxは白でないといけない。
  # uxを根とする部分木の塗り方パターン数を掛け合わせたものが、
  # vを根とする部分木の塗り方のパターン数になる。
  dp = [[0 for _ in range(2)] for _ in range(N)]
  def dfs(v,c,s):
    dp[v][c] = 1
    for u in E[v]:
      if u != s:
        if c == 0: #vが白の場合
          dp[v][c] *= (dfs(u,0,v)+dfs(u,1,v))
        else: #vが黒の場合
          dp[v][c] *= dfs(u,0,v)
    #dp[v][c] %= MOD
    return dp[v][c]

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

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
  N = int(input())
  XY = [tuple(map(int,input().split())) for _ in range(N-1)]
  MOD =10**9+7
  
  E = [[] for _ in range(N)]
  for x,y in XY:
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
  
  def dfs(v,s):
    b = 1
    w = 1
    for u in E[v]:
      if u != s:
        b0,w0 = dfs(u,v)
        b *= w0
        w *= (b0+w0)
    #b %= MOD
    #w %= MOD
    return b,w

  b,w = dfs(0,-1)
  print((b+w) % MOD)

if __name__ == '__main__':
    main()