import sys

input = sys.stdin.readline



n = int(eval(input()))

mod = 10**9+7

g = [[] for _ in range(n)]

for i in range(n-1):

    x, y = list(map(int, input().split()))

    x, y = x-1, y-1

    g[x].append(y)

    g[y].append(x)



dp = [[1, 1] for _ in range(n)]

# dp[v][0]: white

# dp[v][1]: black



s = []

order = []

par = [-1]*n

s.append(0)

while s:

    v = s.pop()

    order.append(v)

    flag = True

    for u in g[v]:

        if u == par[v]:

            continue

        flag = False

        par[u] = v

        s.append(u)



order.reverse()

for v in order:

    if par[v] == -1:

        continue

    dp[par[v]][0] *= (dp[v][0]+dp[v][1])%mod

    dp[par[v]][1] *= dp[v][0]%mod

ans = dp[0][0]+dp[0][1]

#print(dp)

print((ans%mod))
import sys

input = sys.stdin.readline



def main():

    n = int(eval(input()))

    mod = 10**9+7

    g = [[] for _ in range(n)]

    for i in range(n-1):

        x, y = list(map(int, input().split()))

        x, y = x-1, y-1

        g[x].append(y)

        g[y].append(x)



    dp = [[1, 1] for _ in range(n)]

    # dp[v][0]: white

    # dp[v][1]: black



    s = []

    order = []

    par = [-1]*n

    s.append(0)

    while s:

        v = s.pop()

        order.append(v)

        for u in g[v]:

            if u == par[v]:

                continue

            par[u] = v

            s.append(u)



    order.reverse()

    for v in order:

        if par[v] == -1:

            continue

        dp[par[v]][0] *= (dp[v][0]+dp[v][1])%mod

        dp[par[v]][1] *= dp[v][0]%mod

    ans = dp[0][0]+dp[0][1]

    #print(dp)

    print((ans%mod))



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
n = int(eval(input()))
mod = 10**9 + 7
g = [[] for _ in range(n)]
for i in range(n - 1):
    x, y = list(map(int, input().split()))
    x, y = x - 1, y - 1
    g[x].append(y)
    g[y].append(x)
dp = [[1, 1] for _ in range(n)]
# dp[v][0]: white
# dp[v][1]: black
s = []
order = []
par = [-1] * n
s.append(0)
while s:
    v = s.pop()
    order.append(v)
    flag = True
    for u in g[v]:
        if u == par[v]:
            continue
        flag = False
        par[u] = v
        s.append(u)
order.reverse()
for v in order:
    if par[v] == -1:
        continue
    dp[par[v]][0] *= (dp[v][0] + dp[v][1]) % mod
    dp[par[v]][1] *= dp[v][0] % mod
ans = dp[0][0] + dp[0][1]
# print(dp)
print((ans % mod))

import sys

input = sys.stdin.readline


def main():
    n = int(eval(input()))
    mod = 10**9 + 7
    g = [[] for _ in range(n)]
    for i in range(n - 1):
        x, y = list(map(int, input().split()))
        x, y = x - 1, y - 1
        g[x].append(y)
        g[y].append(x)
    dp = [[1, 1] for _ in range(n)]
    # dp[v][0]: white
    # dp[v][1]: black
    s = []
    order = []
    par = [-1] * n
    s.append(0)
    while s:
        v = s.pop()
        order.append(v)
        for u in g[v]:
            if u == par[v]:
                continue
            par[u] = v
            s.append(u)
    order.reverse()
    for v in order:
        if par[v] == -1:
            continue
        dp[par[v]][0] *= (dp[v][0] + dp[v][1]) % mod
        dp[par[v]][1] *= dp[v][0] % mod
    ans = dp[0][0] + dp[0][1]
    # print(dp)
    print((ans % mod))


if __name__ == "__main__":
    main()

-n = int(eval(input())) -mod = 10**9 + 7 -g = [[] for _ in range(n)] -for i in range(n - 1): -    x, y = list(map(int, input().split())) -    x, y = x - 1, y - 1 -    g[x].append(y) -    g[y].append(x) -dp = [[1, 1] for _ in range(n)] -# dp[v][0]: white -# dp[v][1]: black -s = [] -order = [] -par = [-1] * n -s.append(0) -while s: -    v = s.pop() -    order.append(v) -    flag = True -    for u in g[v]: -        if u == par[v]: + + +def main(): +    n = int(eval(input())) +    mod = 10**9 + 7 +    g = [[] for _ in range(n)] +    for i in range(n - 1): +        x, y = list(map(int, input().split())) +        x, y = x - 1, y - 1 +        g[x].append(y) +        g[y].append(x) +    dp = [[1, 1] for _ in range(n)] +    # dp[v][0]: white +    # dp[v][1]: black +    s = [] +    order = [] +    par = [-1] * n +    s.append(0) +    while s: +        v = s.pop() +        order.append(v) +        for u in g[v]: +            if u == par[v]: +                continue +            par[u] = v +            s.append(u) +    order.reverse() +    for v in order: +        if par[v] == -1: -        flag = False -        par[u] = v -        s.append(u) -order.reverse() -for v in order: -    if par[v] == -1: -        continue -    dp[par[v]][0] *= (dp[v][0] + dp[v][1]) % mod -    dp[par[v]][1] *= dp[v][0] % mod -ans = dp[0][0] + dp[0][1] -# print(dp) -print((ans % mod)) +        dp[par[v]][0] *= (dp[v][0] + dp[v][1]) % mod +        dp[par[v]][1] *= dp[v][0] % mod +    ans = dp[0][0] + dp[0][1] +    # print(dp) +    print((ans % mod)) + + +if __name__ == "__main__": +    main()