stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;

#define pb push_back



const int N = 100007;

const int M = 1e9 + 7;



vector<int> e[N];

int memo[N][2]; // vertice e cor do pai



int solve(int u, int c, int p = -1) {

    int & st = memo[u][c];

    if(st == -1) {

        st = 0;



        // pinta de black

        if(c == 0) {

            ll aux = 1;

            for(int v : e[u]) {

                if(v == p) continue;

                aux = aux * solve(v, 1, u) % M;

            }



            st = (st + aux)%M;

        }



        ll aux = 1;

        for(int v : e[u]) {

            if(v == p) continue;

            aux = aux * solve(v, 0, u) % M;

        }



        st = (st + aux)%M;        

    }

    return st;

}



int main() {

    memset(memo, -1, sizeof memo);

    int n; cin >> n;



    for(int i = 0; i < n-1; ++i) {

        int x, y; cin >> x >> y;

        e[x].pb(y);

        e[y].pb(x);

    }



    cout << solve(1, 0) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.3758972119120685x):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

#define for0(i, n) for(int i = 0; i < n; ++i)

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

/*=================================================================================*/



int n, tot, head[N], ver[N<<2], nex[N<<2];

ll dp[N][2];



void add(int x, int y) {

   ver[++tot] = y;

   nex[tot] = head[x];

   head[x] = tot;

}



void dfs(int x, int fa) {

   ll a = 1, b = 1;

   if(nex[head[x]] == 0 && ver[head[x]] == fa) {

      dp[x][0] = dp[x][1] = 1;

      return;

   }

   for(int i = head[x]; i; i = nex[i]) {

      int y = ver[i];

      if(y == fa) continue;

      dfs(y, x);

      a = (a * ((dp[y][0] + dp[y][1]) % mod)) % mod;

      b = (b * dp[y][0]) % mod;

   }

   dp[x][0] = a, dp[x][1] = b;

}



int main() {

   cin>>n;

   for0(i, n-1) {

      int x, y;

      scanf("%d %d", &x, &y);

      add(x, y), add(y, x);

   }

   dfs(1, 0);

   cout << (dp[1][0] + dp[1][1]) % mod << endl;

   return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

#define filein freopen("input.txt","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=200009;

vector<ll > v[mx];

ll  sub[mx];

pair<ll ,ll > call(ll  s, ll  par)

{

    ll  white=1,black=1;

    for(auto x: v[s])

    {

        if(x==par) continue;

        pair<ll ,ll > temp=call(x,s);

        white=white*(temp.first+temp.second);

        white%=mod;

        black=black*temp.first;

        black%=mod;

    }

    return {white,black};

}

int  main()

{



    ll  n;

    cin>>n;

    for(ll  i=0;i<n-1;i++)

    {

        ll  a,b;

        cin>>a>>b;

        v[a].pb(b);

        v[b].pb(a);

    }

    pair<ll ,ll > ans=call(1,-1);

    cout<<(ans.first+ans.second)%mod<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 6.440832229711992x):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

#define for0(i, n) for(int i = 0; i < n; ++i)

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

/*=================================================================================*/



int n, tot, head[N], ver[N<<2], nex[N<<2];

ll dp[N][2];



void add(int x, int y) {

   ver[++tot] = y;

   nex[tot] = head[x];

   head[x] = tot;

}



void dfs(int x, int fa) {

   ll a = 1, b = 1;

   if(nex[head[x]] == 0 && ver[head[x]] == fa) {

      dp[x][0] = dp[x][1] = 1;

      return;

   }

   for(int i = head[x]; i; i = nex[i]) {

      int y = ver[i];

      if(y == fa) continue;

      dfs(y, x);

      a = (a * ((dp[y][0] + dp[y][1]) % mod)) % mod;

      b = (b * dp[y][0]) % mod;

   }

   dp[x][0] = a, dp[x][1] = b;

}



int main() {

   cin>>n;

   for0(i, n-1) {

      int x, y;

      scanf("%d %d", &x, &y);

      add(x, y), add(y, x);

   }

   dfs(1, 0);

   cout << (dp[1][0] + dp[1][1]) % mod << endl;

   return 0;

}
// Slower C++ solution:
//                                      KiSmAt

#include "bits/stdc++.h"

using namespace std;

 

using ll = long long;

 

const ll inf = 1e18;

const int mod = 1e9 + 7;

const int N = 2 * 1e5 + 10;



ll res;

ll a[N];

ll dp[N][3];



vector<ll> v[N];



inline ll add(ll x, ll y){  return  (x % mod + y % mod) % mod;}

inline ll sub(ll x, ll y){  return  (x % mod - y % mod + mod) % mod;}

inline ll mul(ll x, ll y){  x %= mod;   y %= mod;   return 1LL * x * y % mod;}



ll dfs(ll node, ll par, ll prev){

    if(dp[node][prev] + 1)  return dp[node][prev];

    ll xx = 1, yy = 0;

    for(auto i: v[node]){

        if(i != par)    xx = mul(xx, dfs(i, node, 0));

    }

    if(prev < 1){

        yy = 1;

        for(auto i: v[node]){

            if(i != par)    yy = mul(yy, dfs(i, node, prev + 1));

        }

    }

    return dp[node][prev] = add(xx, yy);

}



void solve(){

    ll n, x, y;

    cin >> n;

    for(int i = 0; i < n - 1; ++i){

        cin >> x >> y;

        v[y].push_back(x);

        v[x].push_back(y);

    }

    memset(dp, -1, sizeof dp);

    cout << dfs(1, 1, 0);

}

 

int main(int argc, char const *argv[]){

    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

    ll t = 1;

    //cin >> t;

    while(t--){

        solve();

    }

}

// nEro

// Faster C++ solution for the same problem (measured speedup: 1.8307085308841038x):
//                                      KiSmAt

#include "bits/stdc++.h"

using namespace std;

 

using ll = long long;

 

const ll inf = 1e18;

const int mod = 1e9 + 7;

const int N = 2 * 1e5 + 10;



ll res;

ll a[N], dp[N][2];



vector<ll> v[N];



inline ll add(ll x, ll y){  return  (x % mod + y % mod) % mod;}

inline ll sub(ll x, ll y){  return  (x % mod - y % mod + mod) % mod;}

inline ll mul(ll x, ll y){  x %= mod;   y %= mod;   return 1LL * x * y % mod;}



void dfs(ll u, ll par){

    dp[u][0] = dp[u][1] = 1;

    for(auto i: v[u]){

        if(i != par){

            dfs(i, u);

            dp[u][0] = mul(dp[u][0], dp[i][1]);

            dp[u][1] = mul(dp[u][1], add(dp[i][0], dp[i][1]));

        }

    }

}



void solve(){

    ll n, x, y;

    cin >> n;

    for(int i = 0; i < n - 1; ++i){

        cin >> x >> y;

        v[x].push_back(y);

        v[y].push_back(x);

    }

    dfs(1, 1);

    cout << add(dp[1][0], dp[1][1]);

}

 

int main(int argc, char const *argv[]){

    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

    ll t = 1;

    //cin >> t;

    while(t--){

        solve();

    }

}

// nEro
// Slower C++ solution:
// We only fail when we stop trying

#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define mp make_pair

#define endl '\n'

#define D(x) cerr << #x << " = " << (x) << '\n'

#define sz(x) ((int)(x).size())

#define all(x) (x).begin(), (x).end()

typedef long long ll;



const int N = 1e5 + 5;

const int Mod = 1e9 + 7;





int n;

vector<int> g[N];

int dp[N][2];



int dfs(int u, int p, int col) {

  int& r  = dp[u][col];

  if(r != -1) return r;

  r = 1;

  for(int v : g[u]) {

    if(v != p) {

      if(col == 0) { // b

        r = (1LL * r * dfs(v, u, 1)) % Mod;

      } else { // w

        r = (1LL * r * (dfs(v, u, 0) + dfs(v, u, 1))) % Mod;

      }

    }

  }

  return r;

}



int main()

{

  cin >> n;

  for(int i = 0; i < n - 1; i++) {

    int x, y;

    cin >> x >> y;

    --x, --y;

    g[x].pb(y);

    g[y].pb(x);

  }

  memset(dp, -1, sizeof dp);

  cout << (dfs(0, -1, 1) + dfs(0, -1, 0)) % Mod << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2384610747203373x):
// We only fail when we stop trying

#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define mp make_pair

#define endl '\n'

#define D(x) cerr << #x << " = " << (x) << '\n'

#define sz(x) ((int)(x).size())

#define all(x) (x).begin(), (x).end()

typedef long long ll;



const int N = 1e5 + 5;

const int Mod = 1e9 + 7;





int n;

vector<int> g[N];

int dp[N][2];



void dfs(int u, int p) {

  dp[u][0] = dp[u][1] = 1;

  for(int v : g[u]) {

    if(v != p) {

      dfs(v, u);

      dp[u][0] = (1LL * dp[u][0] * dp[v][1]) % Mod;

      dp[u][1] = (1LL * dp[u][1] * (dp[v][0] + dp[v][1])) % Mod;

    }

  }

}



int main()

{

  cin >> n;

  for(int i = 0; i < n - 1; i++) {

    int x, y;

    cin >> x >> y;

    --x, --y;

    g[x].pb(y);

    g[y].pb(x);

  }

  dfs(0, -1);

  int ans = (dp[0][0] + dp[0][1]) % Mod;

  cout << ans << endl;

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

using namespace std;



typedef long long llt;



const int MaxN = 100000 + 5, MaxM = 200000 + 5;

const llt Mod = 1e9 + 7;



int N; int cnte;

int Head[MaxN], To[MaxM], Next[MaxM];

int fa[MaxN];

llt dp[MaxN][2];



inline void add_edge(int from, int to) {

  cnte++; To[cnte] = to;

  Next[cnte] = Head[from]; Head[from] = cnte;

}



void init() {

  scanf("%d", &N);

  for (int i = 1; i < N; ++i) {

    int u, v;

    scanf("%d %d", &u, &v);

    add_edge(u, v); add_edge(v, u);

  }

}



void dfs(int u) {

  dp[u][0] = dp[u][1] = 1;

  for (int i = Head[u]; i; i = Next[i]) {

    int v = To[i];

    if (v == fa[u]) continue;

    fa[v] = u;

    dfs(v);



    dp[u][0] = dp[u][0] * (dp[v][0] + dp[v][1]) % Mod;

    dp[u][1] = dp[u][1] * dp[v][0] % Mod;

  }

}



void solve() {

  dfs(1);

  llt ans = (dp[1][0] + dp[1][1]) % Mod;

  cout << ans << endl;

}



int main() {

  init();

  solve();

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.178363884497097x):
#include <cstdio>



const int MaxN = 100000 + 5;

const int Mod = 1000000007;



struct Graph {

  int cnte;

  int Head[MaxN], To[MaxN * 2], Next[MaxN * 2];



  inline void addEdge(int from, int to) {

    cnte++; To[cnte] = to;

    Next[cnte] = Head[from]; Head[from] = cnte;

  }

};



int N;

int Dp[MaxN][2];

Graph G;



inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }

inline int mul(int x, int y) { return 1LL * x * y % Mod; }



void init() {

  scanf("%d", &N);

  for (int i = 1; i < N; ++i) {

    int u, v;

    scanf("%d %d", &u, &v);

    G.addEdge(u, v);

    G.addEdge(v, u);

  }

}



void dfs(int u, int f) {

  Dp[u][0] = Dp[u][1] = 1;

  for (int i = G.Head[u]; i; i = G.Next[i]) {

    int v = G.To[i];

    if (v == f) continue;

    dfs(v, u);

    Dp[u][0] = mul(Dp[u][0], add(Dp[v][0], Dp[v][1]));

    Dp[u][1] = mul(Dp[u][1], Dp[v][0]);

  }

}



void solve() {

  dfs(1, 0);

  printf("%d\n", add(Dp[1][0], Dp[1][1]));

}



int main() {

  init();

  solve();

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define pu_b push_back



using namespace std;



const int N=1e5+10, Mod=1e9+7;

int n, max_floor=0;

ll dp[2][N];

int dis[N], par[N];

bool visible[N]={};

vector<int> adj[N], flor[N];



void dfs(int x){

    for(int v:adj[x]){

        if(visible[v]) continue;

        visible[v]=1;

        dis[v]=dis[x]+1;

        flor[dis[v]].pu_b(v);

        max_floor=max(max_floor, dis[v]);

        par[v]=x;

        dfs(v);

    }

}



int main()

{

    cin>>n;

    for(int i=0; i<n-1; i++){

        int x, y;

        cin>>x>>y;

        x--; y--;

        adj[x].pu_b(y);

        adj[y].pu_b(x);

    }

    dis[0]=0;

    visible[0]=1;

    flor[0].pu_b(0);

    dfs(0);

    //Computing dp

    int t=max_floor;

    for(int u:flor[max_floor]){

        dp[0][u]=1;

        dp[1][u]=2;

    }

    for(int i=max_floor-1; i>=0; i--){

        for(int p:flor[i]){

            ll blval=1, whval=1;

            for(int v:adj[p]){

                if(v!=par[p]){

                    blval=(blval*dp[0][v])%Mod;

                    whval=(whval*dp[1][v])%Mod;

                }

            }

            dp[0][p]=whval;

            dp[1][p]=(blval+whval)%Mod;

        }

    }

    cout<<dp[1][0];

}
















































// Faster C++ solution for the same problem (measured speedup: 1.8106003004775992x):
#include <bits/stdc++.h>

#define ll long long

#define PuB push_back



using namespace std;



const int N=1e5+10, Mod=1e9+7;

int n;

ll dp[2][N];

int par[N];

bool visible[N]={};

vector<int> adj[N];



void dfs(int x){

    bool leaf=1;

    for(int v:adj[x]){

        if(v!=par[x]){

            leaf=0;

            if(visible[v]) continue;

            par[v]=x;

            visible[v]=1;

            dfs(v);

        }

    }

    if(leaf){

        dp[0][x]=1;

        dp[1][x]=2;

        return;

    }

    ll blval=1, whval=1;

    for(int u:adj[x]){

        if(u!=par[x]){

            blval*=dp[0][u];

            blval%=Mod;

            whval*=dp[1][u];

            whval%=Mod;

        }

    }

    dp[0][x]=whval;

    dp[1][x]=(whval+blval)%Mod;

}



int main()

{

    cin>>n;

    for(int i=0; i<n-1; i++){

        int x, y;

        cin>>x>>y;

        x--; y--;

        adj[x].PuB(y);

        adj[y].PuB(x);

    }

    par[0]=-1;

    visible[0]=1;

    dfs(0);

    cout<<dp[1][0];

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#ifdef LOCAL

        ifstream in("input.txt");

        //ofstream out("output.txt");

        #define cin in

        //#define cout out

#endif

int const MAXN=110000, M=1000000007;

long long int bianco[MAXN], nero[MAXN], n;

vector<int> g[MAXN], t[MAXN];

void make_tree(int node=1, int parent=-1){

	for(auto x:g[node])

		if(x!=parent){

			t[node].push_back(x);

			make_tree(x,node);

		}

}

void dp(int node=1){

	if(t[node].empty()){

		bianco[node]=1LL;

		nero[node]=1LL;

	}

	else{

		for(auto x:t[node])

			dp(x);

		nero[node]=1LL;

		for(auto x:t[node]){

			nero[node]*=bianco[x];

			nero[node]%=M;

		}

		bianco[node]=1LL;

		for(auto x:t[node]){

			bianco[node]*=nero[x]+bianco[x];

			bianco[node]%=M;

		}

	}

}

int main(){

	cin>>n;

	for(int i=0;i<n-1;i++){

		int from, to;

		cin>>from>>to;

		g[from].push_back(to);

		g[to].push_back(from);

	}

	make_tree();

	dp();

	cout<<(nero[1]+bianco[1])%M;

}

// Faster C++ solution for the same problem (measured speedup: 1.9829254177195337x):
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

void dbg_out(){

	cerr<<endl;

}

template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){

	cerr<<' '<< H; 

	dbg_out(T...);

}

int const MAXN=100100, MOD=1e9+7;

#define ll long long

vector<int> tree[MAXN];

ll w[MAXN], b[MAXN], n;

void dp(int node, int parent){

	w[node]=b[node]=1;

	for(int x:tree[node])

		if(x!=parent){

			dp(x,node);

			b[node]=(b[node]*w[x])%MOD;

			w[node]=((w[x]+b[x])%MOD*w[node])%MOD;

		}

	//dbg(node,parent,b[node],w[node]);	

}

int main(){

	cin>>n;

	for(int i=0;i<n-1;i++){

		int a, b;

		cin>>a>>b;

		tree[a].push_back(b);

		tree[b].push_back(a);

	}

	dp(1,0);

	cout<<(w[1]+b[1])%MOD;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std ;

#define ll long long 

vector<int> edges[100005];

int mod=1e9+7;

ll mul(ll a,ll b){

	return a*b%mod;

}

pair<ll,ll> dfs(int a,int parent){

	ll allwhite=1;

	ll smblack=0;

	for(auto b:edges[a]){

		if(b!=parent){

			pair<ll,ll>p=dfs(b,a);

		

		smblack= (mul(allwhite,p.first)+mul(smblack,p.first+p.second))%mod;

		allwhite*=p.second;

		allwhite%=mod;

		}

	}

	return{allwhite,(allwhite+smblack)%mod};

}



int main(){

	ll n;

	cin>>n;

	for(int i=0;i<n-1;i++){

		int a,b;

		cin>>a>>b;

		edges[a].push_back(b);

		edges[b].push_back(a);

	}

	pair<ll,ll>p=dfs(1,-1);

	

	cout<<(p.first+p.second)%mod;

	

	

	

	

	return 0;

	

}


// Faster C++ solution for the same problem (measured speedup: 3.524810057870075x):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int mod=1e9+7;

vector<vector<int>>adj;

pair<ll,ll> dfs(int i,int p){

    ll all_white=1;

    ll sm_black=0;

    for(int u:adj[i]){

        if(u!=p){

            pair<ll,ll>p=dfs(u,i);

            sm_black=(all_white*p.first%mod+sm_black*(p.first+p.second)%mod)%mod;

            all_white=all_white*p.second%mod;



        }

    }

    return{all_white,all_white+sm_black};



}



int main(){

    int n;

    cin>>n;

    adj=vector<vector<int>>(n+1);

    int x,y;

    for(int i=0;i<n-1;i++){

        cin>>x>>y;

        adj[x].push_back(y);

        adj[y].push_back(x);

    }

    pair<ll,ll>p=dfs(1,-1);

    cout<<(p.first+p.second)%mod;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int N = 1e5 + 5;

long long dp[N][2];

vector<int>a[N];

const int m = 1e9 + 7;

long long solve(int u, int c, int p){

    if(dp[u][c] != -1) return dp[u][c];

    long long ans = 1;

    for(auto v : a[u]){

        if(v == p) continue;

        if(c == 0){

            ans = (ans *(solve(v, 0, u) + solve(v, 1, u)) )%m;

        }

        else ans = (ans * solve(v, 0, u)) % m;

    }

    dp[u][c] = ans;

    return ans;

}

int main(){

    int n, x, y;

    cin >> n;

    for(int i = 1; i < n; i++){

        cin >> x >> y;

        x --, y --;

        a[x].push_back(y);

        a[y].push_back(x);

    }

    memset(dp, -1, sizeof(dp));

    long long ans = (solve(0, 0, -1) + solve(0, 1, -1))%m;

    cout << ans << "\n";

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.224797084794828x):
#include<bits/stdc++.h>

using namespace std;



const int N = 1e5 + 5;

long long dp[N];

vector<int>a[N];

vector<bool>isvisited(N, false);

const int m = 1e9 + 7;

long long solve(int u,int p){

    if(dp[u] != -1)return dp[u];

    long long ans1 = 1,ans2 = 1;

    for(auto v: a[u]){

        if(v == p) continue;

        ans1 = (ans1 * solve(v, u)) % m;

        for(auto w : a[v]){

            if(w == u) continue;

            ans2 = (ans2 * solve(w,v)) % m;

        }

    }

    dp[u] = (ans1 + ans2)%m;

    return dp[u];

}

int main(){

    int n, x, y;

    cin >> n;

    for(int i = 1; i < n; i++){

        cin >> x >> y;

        x --, y --;

        a[x].push_back(y);

        a[y].push_back(x);

    }

    memset(dp, -1, sizeof(dp));  

    solve(0, -1);

    cout << dp[0] << endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<ll> vec;

typedef vector<vec> mat;

typedef pair<ll,ll> pll;

const ll mod=1e9+7;

//const ll mod=998244353;

const ll inf=5e15;



const ll N=1e5+10;

vector<set<ll>> G(N);

vec b(N),w(N);

ll n;



void dfs(ll cur,ll pre) {

  b[cur]=1,w[cur]=1;

  for(ll nex:G[cur]) {

    if(nex==pre) continue;

    dfs(nex,cur);

    (b[cur]*=w[nex])%=mod;

    (w[cur]*=(w[nex]+b[nex])%mod)%=mod;

  }

}

 

int main() {

  cin >> n;

  for(ll i=1;i<n;i++) {

    ll x,y;

    cin >> x >> y;

    x--,y--;

    G[x].insert(y);

    G[y].insert(x);

  }

  dfs(0,-1);

  cout << (b[0]+w[0])%mod << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.4931419926273772x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<ll> vec;

typedef vector<vec> mat;

typedef pair<ll,ll> pll;

const ll mod=1e9+7;

//const ll mod=998244353;

const ll inf=1LL<<61;



const ll N=1e5+10;

mat G(N);

vec w(N),b(N);



void dfs(ll cur,ll pre) {

  w[cur]=1,b[cur]=1;

  for(ll nex:G[cur]) {

    if(nex==pre) continue;

    dfs(nex,cur);

    (b[cur]*=w[nex])%=mod;

    (w[cur]*=w[nex]+b[nex])%=mod;

  }

}



int main() {

  ll n;

  cin >> n;

  for(ll i=0;i<n-1;i++) {

    ll x,y;

    cin >> x >> y;

    x--,y--;

    G[x].push_back(y);

    G[y].push_back(x);

  }

  dfs(0,-1);

  cout << (w[0]+b[0])%mod << endl;

}
// Slower C++ solution:
/*#include <bits/stdc++.h>

using namespace std;

long long n;

vector<long long>v[100009];

long long mod = 1000000007;

long long dp[100009][3];

void dfs(int node,int p){

	dp[node][0] = dp[node][1] = 1;

	for(int i=0;i<v[node].size();i++){

		int u = v[node][i];

		if(u == p)continue;

		dfs(u,node);

		dp[node][0] = (dp[node][0] * (dp[u][0] + dp[u][1])%mod)%mod;

		dp[node][1] = (dp[node][1] * dp[u][0])%mod;

	}

}

int main(){

	cin>>n;

	for(int i=0;i<n-1;i++){

		int a,b;

		cin>>a>>b;

		a--;b--;

		v[a].push_back(b);

		v[b].push_back(a);

	}

	dfs(0,0);

	cout<<dp[0][0] + dp[0][1]<<endl;

}*/

#include <bits/stdc++.h>

using namespace std;

long long n;

vector<long long>v[100009];

long long dp[100009][3];

long long mod=1000000007;

long long bt(int node,int p,int t){

	long long &ret=dp[node][t];

	if(ret!=-1)return ret;

	ret=1;

	for(int i=0;i<v[node].size();i++){

		int u=v[node][i];

		if(u==p)continue;

		if(t==1)ret=(ret%mod*bt(u,node,0)%mod)%mod;

		else if(t==0)ret=(ret%mod*(bt(u,node,1)%mod+bt(u,node,0)%mod)%mod)%mod;

	}

	return ret%mod;

}

int main(){

	memset(dp,-1,sizeof(dp));

	cin>>n;

	for(int i=0;i<n-1;i++){

		int a,b;

		cin>>a>>b;

		a--;b--;

		v[a].push_back(b);

		v[b].push_back(a);

	}

	cout<<(bt(0,0,0)%mod+bt(0,0,1)%mod)%mod<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.775207798091491x):
#include <bits/stdc++.h>

using namespace std;

long long n;

vector<long long>v[100009];

long long mod = 1000000007;

long long dp[100009][3];

void dfs(int node,int p){

 	dp[node][0] = dp[node][1] = 1;

   	for(int i=0;i<v[node].size();i++){

   		int u = v[node][i];

   		if(u == p)continue;

   		dfs(u,node);

   		dp[node][0] = (dp[node][0] * (dp[u][0] + dp[u][1])%mod)%mod;

   		dp[node][1] = (dp[node][1] * dp[u][0])%mod;

   	}

}

int main(){

   	cin>>n;

   	for(int i=0;i<n-1;i++){

   		int a,b;

   		cin>>a>>b;

   		a--;b--;

   		v[a].push_back(b);

   		v[b].push_back(a);

   	}

   	dfs(0,0);

   	cout<<(dp[0][0] + dp[0][1]) % mod<<endl;

}