Problem:
Score : 100 points

Problem Statement

There is a tree with N vertices, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.

Taro has decided to paint each vertex in white or black.
Here, it is not allowed to paint two adjacent vertices both in black.

Find the number of ways in which the vertices can be painted, modulo 10^9 + 7.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq x_i, y_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1}

Output

Print the number of ways in which the vertices can be painted, modulo 10^9 + 7.

Sample Input 1

3
1 2
2 3

Sample Output 1

5

There are five ways to paint the vertices, as follows:

Sample Input 2

4
1 2
1 3
1 4

Sample Output 2

9

There are nine ways to paint the vertices, as follows:

Sample Input 3

1

Sample Output 3

2

Sample Input 4

10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7

Sample Output 4

157

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
#define getb __builtin_popcount

const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;
 
using namespace std;

ll dp[N][2]; // number of ways to paint subtree with white or black root
// 0 - white
// 1 - black
vector<int> v[N];
int root = 0;

void dfs(int p, int x)
{
	if(v[x].si == 1 && x != root)	dp[x][0] = dp[x][1] = 1;
	ll cur1 = 1, cur2 = 1;
	for(auto i:v[x])
	{
		if(i != p)
		{
			dfs(x, i);
			cur1 *= (dp[i][0] + dp[i][1]);
			cur2 *= dp[i][0];
			cur2 %= modw;
			cur1 %= modw;
		}
	}
	dp[x][0] = cur1;
	dp[x][1] = cur2;
}

int main()
{
	barnarnar
	int n;
	cin >> n;
	if(n == 1)
	{
		cout << 2;
		r0;
	}
	forn(i, n - 1)
	{
		int t1, t2;
		cin >> t1 >> t2;
		v[t1].pb(t2);
		v[t2].pb(t1);
	}
	forn1(i, n)
	{
		if(v[i].si == 1)
		{
			root = i;
			break;
		}
	}
	dfs(0, root);
	/*
	cout << root << endl;
	for(int i = 1; i <= n; i++)
	{
		cout << "i: " << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
	*/
	cout << (dp[root][0] + dp[root][1]) % modw;
	return 0;
}