stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/*

 * Author : Andrew J

*/

#include <bits/stdc++.h>

using namespace std;

#define fi first

#define se second

#define pb push_back

using ll = long long;

using ii = pair <ll , ll>;

void in(ll &x);

const ll N = 1e5 + 10;

const ll INF = 1e9;

const ll M = 1e9 + 7;

ll n;

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

vector <ll> adj[N];



void makeRooted() {

  fill (d , d + N , INF);

  queue <ii> q;

  q.push({1 , 0});

  while (q.size()) {

    ii cur = q.front(); q.pop();

    ll u = cur.fi, cd = cur.se;

    if (d[u] != INF) continue;

    d[u] = cd;

    for (ll v : adj[u]) {

      q.push({v , cd + 1});

    }

  }

  return;

}



ll add(ll a , ll b) {

  return ((a % M) + (b % M)) % M;

}



ll mul(ll a , ll b) {

  return ((a % M) * (b % M)) % M;

}



ll f(ll u , bool col) {

  ll &sol = dp[u][col];

  if (sol != -1) return sol;

  sol = 1;

  for (ll v : adj[u]) {

    if (d[v] < d[u]) continue;

    ll cur = 0;

    if (col) {

      cur = add(cur , f(v , !col));

    } else {

      cur = add(cur , add(f(v , !col) , f(v , col)));

    }

    sol = mul(sol , cur);

  }

  return sol;

}



int main() {

  in(n);

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

    in(u); in(v);

    adj[u].pb(v);

    adj[v].pb(u);

  }

  makeRooted();

  memset (dp , -1 , sizeof dp);

  printf("%lld\n" , add(f(1 , 0) , f(1 , 1)));

  return 0;

}



void in(ll &x){

	bool neg = false;

	register ll c;

	x = 0;

	c = getchar();

	if(c == '-'){

		neg = true;

		c = getchar();

	}

	for (; c > 47 && c < 58; c = getchar())

	x = (x << 1) + (x << 3) + c - 48;

	if (neg) x *= -1;

}


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

using namespace std;



#define pb push_back

#define ll long long

#define MOD 1000000007



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

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

using namespace std;



typedef long long int ll;

const ll maxn = 100010;

const ll mod = 1000000007;

vector <ll> adj[maxn];

ll dp[maxn][3];



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

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

    ll ans = 1;

    for(auto x: adj[node]){

        if(x != par){

            if(col == 1){

                ans *= dfs(x,0,node);

                ans %= mod;

            }

            else{

                ans = ans * (dfs(x,0,node) + dfs(x,1,node));

                ans %= mod;

            }

        }

    }



    return dp[node][col] = ans;

}

int main(){

    memset(dp,-1,sizeof dp);

    ll n;

    scanf("%lld",&n);



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

        ll u,v;

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

        adj[u].push_back(v);

        adj[v].push_back(u);

    }



    printf("%lld\n",(dfs(1,0,-1)+dfs(1,1,-1))%mod);

}


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

using namespace std;



#define ll long long

#define MOD 1000000007

#define pb push_back



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

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



//#pragma GCC optimize("Ofast")

//#pragma comment(linker, "/stack:200000000")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4"



#define mp make_pair

#define pb push_back

#define f first

#define s second

#define ll long long

#define int ll

#define forn(i, a, b) for(int i = (a); i <= (b); ++i)

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define VAR(v, i) __typeof( i) v=(i)

#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

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

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

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

 

using namespace std;

 

const int maxn = (int)1e5+100;

const int mod = (int)1e9 + 7;

 

#define inf mod

 

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;   

typedef vector<ll> Vll;               

typedef vector<pair<int, int> > vpii;

typedef vector<pair<ll, ll> > vpll;



int n, dp[maxn][2];

vi g[maxn];



void dfs(int v, int p = 0){

  dp[v][0]=dp[v][1]=1;

  for(auto to:g[v])

    if(to!=p){

      dfs(to,v);

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

      dp[v][1]=dp[v][1]*dp[to][0]%mod;

    }

}

main () {

  cin>>n;

  forn(i,1,n-1){

    int u, v;

    cin>>u>>v;

    g[u].pb(v);

    g[v].pb(u);

  }

  dfs(1);

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

}

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

using namespace std;



#define ll long long

#define MOD 1000000007

#define pb push_back



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

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



using namespace std;

 

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

 

#define nl '\n'

 

#define y1 aza_ibagaliev

 

#define f first

#define s second

	

#define ed end()

#define bg begin()

#define rbg rbegin()

 

#define rv reverse

#define mp make_pair

#define pb push_back

#define ppb pop_back

#define ppf pop_front

 

#define sz size()

#define all(x) x.bg, x.ed

 

#define pll pair < ll, ll >

#define pii pair < int, int >

 

#define sqr(x) ((x) * 1ll * (x))

#define sqrd(x) ((x) * 1.0 * (x))

 

#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

 

#define rnl cout << "----------------------------------------" << nl

 

#define bit __builtin_popcount

 

inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

        	

const int ppr = 257;

const ll INF = 2e18;

const int inf = 2e9;

const int mod = 1e9 + 7;

const int N = 1e5 + 123;

const ld pi = 3.1741592653589793238462643;

 

const int dx[] = {1, 0, -1, 0};

const int dy[] = {0, 1, 0, -1};



ll n, dp[3][N];

vector<int>g[N];



void dfs(int v, int pr=0) {

	dp[0][v] = dp[1][v] = 1;



	for(int to : g[v]) {

		if(to == pr) continue;

		dfs(to, v);	

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

		dp[1][v] = (dp[1][v] * dp[0][to]) % mod;

	}

}



main() {             	

//  freopen(".in", "r", stdin);

//  freopen(".out", "w", stdout);



//	srand(time(NULL));



	scanf("%d", &n);



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

		int x, y;

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

		g[x].pb(y);

		g[y].pb(x);

	}



	dfs(1);



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

    

    return 0;                                        

}

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

using namespace std;



#define ll long long

#define MOD 1000000007

#define pb push_back



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

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



using namespace std;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>





#define f first

#define s second

#define db long double

#define pb push_back

#define sz(c) (c).size()

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



typedef long long ll;

typedef pair <int , int> ii;

typedef pair <ii , int> iii;

typedef vector <int> vi;

typedef vector <ii> vii;

typedef vector <iii> viii;

typedef vector <vi> vvi;

typedef vector <vii> vvii;



const ll mod = 1e9+7;

const int MAX = 1e5+5;

const db eps = 1e-13;



int memo[MAX][2];

int n;

vvi g;



int dp( int node, int color , int p = -1 ) {



    if( memo[node][color] != -1 )

        return memo[node][color];



    int &res = memo[node][color];

    res = 1;

    if( sz(g[node]) == 1 && p != -1 ) {



        return res = res + (!color);



    }



    ll res1 = 1;

    ll res2 = 1;



    for( int nw: g[node] ) {

        if( nw==p )

            continue;



        if( !color )

            res1 = ( 1ll * res1 * dp( nw , color , node ) ) % mod;

        res2 = ( 1ll * res2 * dp( nw , color^1 , node ) ) % mod;

    }

    return res = ((!color)*res1+res2)%mod;

}





int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

    cout<<setprecision(11)<<fixed;



    memset( memo , -1 , sizeof memo );

    cin>>n;

    if( n==1 ) {

        cout<<2<<"\n";

        return 0;

    }



    vi v;

    g = vvi(n+1,v);

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

        int a, b;

        cin>>a>>b;

        g[a].pb(b);

        g[b].pb(a);

    }

    cout<<dp( 1 , 0 )<<"\n";



}

/*

10

8 5

10 8

6 5

1 5

4 8

2 10

3 6

9 2

1 7

*/

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

using namespace std;



#define ll long long

#define MOD 1000000007

#define pb push_back



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

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

#include<iostream>

using namespace std;

const int MAXN = 100010;

const int MOD = 1e9+7;

int n;

struct edge{

	int next, to;

	edge(int N=0,int T=0):next(N),to(T){}

}e[MAXN<<1];

int fir[MAXN], num = 0;

inline void join(int a,int b){e[++num]=edge(fir[a],b);fir[a]=num;}

int f[MAXN][2];

void dfs(int u, int fa)

{

	f[u][0] =1ll; f[u][1] = 1ll;

	for(int i=fir[u];i;i=e[i].next)

	{

		int v = e[i].to;

		if(v == fa)continue;

		dfs(v, u);

		f[u][1] = 1ll*f[u][1]*f[v][0]%MOD;

		f[u][0] = 1ll*f[u][0]*(1ll*f[v][0]+f[v][1])%MOD; 

	}

}

int main()

{

	scanf("%d",&n);

	for(int i=1,a,b;i<n;i++)

		scanf("%d%d",&a,&b),join(a,b),join(b,a);

	dfs(1, 0);

	printf("%d\n",(1ll*f[1][0]+f[1][1])%MOD);

	return 0;

}

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

using namespace std;



#define ll long long

#define MOD 1000000007

#define pb push_back



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

}
// Slower C++ solution:
/*

 * Author : Andrew J

*/

#include <bits/stdc++.h>

using namespace std;

#define fi first

#define se second

#define pb push_back

using ll = long long;

using ii = pair <ll , ll>;

void in(ll &x);

const ll N = 1e5 + 10;

const ll INF = 1e9;

const ll M = 1e9 + 7;

ll n;

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

vector <ll> adj[N];



void makeRooted() {

  fill (d , d + N , INF);

  queue <ii> q;

  q.push({1 , 0});

  while (q.size()) {

    ii cur = q.front(); q.pop();

    ll u = cur.fi, cd = cur.se;

    if (d[u] != INF) continue;

    d[u] = cd;

    for (ll v : adj[u]) {

      q.push({v , cd + 1});

    }

  }

  return;

}



ll add(ll a , ll b) {

  return ((a % M) + (b % M)) % M;

}



ll mul(ll a , ll b) {

  return ((a % M) * (b % M)) % M;

}



ll f(ll u , bool col) {

  ll &sol = dp[u][col];

  if (sol != -1) return sol;

  sol = 1;

  for (ll v : adj[u]) {

    if (d[v] < d[u]) continue;

    ll cur = 0;

    if (col) {

      cur = add(cur , f(v , !col));

    } else {

      cur = add(cur , add(f(v , !col) , f(v , col)));

    }

    sol = mul(sol , cur);

  }

  return sol;

}



int main() {

  in(n);

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

    in(u); in(v);

    adj[u].pb(v);

    adj[v].pb(u);

  }

  makeRooted();

  memset (dp , -1 , sizeof dp);

  printf("%lld\n" , add(f(1 , 0) , f(1 , 1)));

  return 0;

}



void in(ll &x){

	bool neg = false;

	register ll c;

	x = 0;

	c = getchar();

	if(c == '-'){

		neg = true;

		c = getchar();

	}

	for (; c > 47 && c < 58; c = getchar())

	x = (x << 1) + (x << 3) + c - 48;

	if (neg) x *= -1;

}


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

using namespace std;



#define ll long long

#define MOD 1000000007

#define pb push_back



class grafo {

	int n;

	vector<vector<pair<int, int>>> adj;



public:



    vector<ll> dp_preto, dp_branco;



	grafo(int n) {

		this->n = n;

		adj = vector<vector<pair<int, int>>>(n);

        dp_preto = vector<ll>(n, 1);

        dp_branco = vector<ll>(n, 1);

	}



	void aresta(int u, int v, int w) {

		adj[u].pb({v, w});

		adj[v].pb({u, w});

	}



    void dfs(int u, int pai = -1) {

        for (auto &v : adj[u]) {

            if (v.first == pai) continue;

            dfs(v.first, u);

            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);

            dp_preto[u] *= dp_branco[v.first];

            dp_branco[u] %= MOD;

            dp_preto[u] %= MOD;

        }

	}



};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n;

    grafo g(n);

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

        cin >> x >> y;

        g.aresta(x-1, y-1, 1);

    }

    g.dfs(0);

    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;

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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int N;

vector<int> V[100001];

int D[100001];

ll mod = 1e9 + 7;



pair<ll, ll> dfs(int A) {

	if (D[A]) return mp(0, 1);

	D[A] = 1;

	ll kuro = 1;

	ll siro = 1;

	for (int i : V[A]) {

		auto k = dfs(i);

		kuro = (kuro * k.second) % mod;

		siro = (siro * (k.first + k.second)) % mod;

	}

	return mp(kuro, siro);

}







int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	cin >> N;

	rep(i, N - 1) {

		int x, y;

		cin >> x >> y;

		V[x].pb(y);

		V[y].pb(x);

	}



	auto M = dfs(1);

	co((M.first + M.second) % mod);



	Would you please return 0;

}

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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int N;

int to[200001], ne[200001], he[100001];

ll mod = 1e9 + 7;

pair<ll, ll> dfs(int A, int prev) {

	ll kuro = 1;

	ll siro = 1;

	for (int i = he[A]; i; i = ne[i]) {

		int To = to[i];

		if (To != prev) {

			auto k = dfs(To, A);

			kuro = (kuro * k.second) % mod;

			siro = (siro * k.first) % mod;

		}

	}

	return mp(kuro + siro, siro);

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	cin >> N;

	int k = 1;

	rep(i, N - 1) {

		int x, y;

		cin >> x >> y;

		to[k] = y;

		ne[k] = he[x];

		he[x] = k++;

		to[k] = x;

		ne[k] = he[y];

		he[y] = k++;

	}



	auto M = dfs(1, 0);

	co(M.first % mod);



	Would you please return 0;

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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int N;

vector<int> V[100001];

int D[100001];

ll mod = 1e9 + 7;



pair<ll, ll> dfs(int A) {

	if (D[A]) return mp(0, 1);

	D[A] = 1;

	ll kuro = 1;

	ll siro = 1;

	for (int i : V[A]) {

		auto k = dfs(i);

		kuro = (kuro * k.second) % mod;

		siro = (siro * (k.first + k.second)) % mod;

	}

	return mp(kuro, siro);

}







int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	cin >> N;

	rep(i, N - 1) {

		int x, y;

		cin >> x >> y;

		V[x].pb(y);

		V[y].pb(x);

	}



	auto M = dfs(1);

	co((M.first + M.second) % mod);



	Would you please return 0;

}

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

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int N;

int to[200001], ne[200001], he[100001];

ll mod = 1e9 + 7;

pair<ll, ll> dfs(int A, int prev) {

	ll kuro = 1;

	ll siro = 1;

	for (int i = he[A]; i; i = ne[i]) {

		int To = to[i];

		if (To != prev) {

			auto k = dfs(To, A);

			kuro = (kuro * k.second) % mod;

			siro = (siro * k.first) % mod;

		}

	}

	return mp(kuro + siro, siro);

}



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	N = getint();

	int k = 1;

	rep(i, N - 1) {

		int x = getint(), y = getint();

		to[k] = y;

		ne[k] = he[x];

		he[x] = k++;

		to[k] = x;

		ne[k] = he[y];

		he[y] = k++;

	}



	auto M = dfs(1, 0);

	printf("%lld", M.first % mod);



	Would you please return 0;

}