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++ (Clang 10.0.0) (judge verdict: Wrong Answer)

//
//  main.cpp
//  DPp
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using P=pair<int,int>;
using ll = long long;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MX = 100005;
vector<vector<int>>v(MX); // 頂点データ
int num=-MX;
int order[MX]={}; // 根からの番号を管理する
mint dp[100005][2]={}; // 調査結果
vector<vector<bool>> flag(100005,vector<bool>(2,false));
mint f(int i,int j){ // i:親 j=0:黒 j=1:白
    if(flag.at(i).at(j)==true) return dp[i][j];
    if(order[i]>num) order[i]=num; // 調査する順番、既に調査した頂点は書き換えない。子から戻る時に親に戻る時の判定にも使うため
    num++;
    int count=0;
    int my_oder=order[i];
    rep(x,v.at(i).size()){
        if(order[v.at(i).at(x)]>my_oder)count++;
    }
    if (count==0) {
        flag[i][j]=true;
        return dp[i][j]=1; // 子がない頂点は1を返す
    }
    mint sum=1;
    mint sum_w=1;
    if (j==0) { // 黒
        rep(x,v.at(i).size()){
            int now=v.at(i).at(x);
            if (order[now]>my_oder) sum*=f(now,1); // 自分より後ろの頂点だけ計算する
        }
        flag[i][j]=true;
        return dp[i][j]=sum;
    } else { // 白
        rep(x,v.at(i).size()){
            int now=v.at(i).at(x); // 自分より後ろの頂点だけ計算する
            if (order[now]>my_oder) sum_w*=(f(now,1)+f(now,0));
        }
        flag[i][j]=true;
        return dp[i][j]=sum_w;
    }
}
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int x,y;
    rep(i,n-1){
        cin>>x;
        cin>>y;
        v.at(x).push_back(y);
        v.at(y).push_back(x);
    }
    cout<<f(1,1)+f(1,0)<<endl;
    return 0;
}