stablegradients/pie-gem5-pairs huggingface dataset:
// 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;

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;

}

// Faster C++ solution for the same problem (measured speedup: 5.383029679969604x):
//#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;

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

using namespace std;

#define ll long long

#define MOD 1000000007

#define sz 100100



ll dp[sz][2];



inline ll mul(ll a, ll b)

{

	a = ((a % MOD) + MOD) % MOD;

	b = ((b % MOD) + MOD) % MOD;

	return (a * b) % MOD;

}



inline ll add(ll a, ll b)

{

	a = ((a % MOD) + MOD) % MOD;

	b = ((b % MOD) + MOD) % MOD;

	return (a + b) % MOD;

}



vector<int>adj[sz];



ll dfs(int rt, bool st, int par)

{



	if (adj[rt].size() == 1 && adj[rt][0] == par)

	{

		if (st)

			return 2;

		return 1;

	}



	ll &ans = dp[rt][st];

	if (ans != -1)

		return ans;



	ans = 1;



	for (auto it : adj[rt])

	{

		if (it == par)

			continue;

		ans = mul(ans, dfs(it, 1, rt));

	}



	if (st)

	{

		ll ans2 = 1;

		for (auto it : adj[rt])

		{

			if (it == par)

				continue;

			ans2 = mul(ans2, dfs(it, 0, rt));

		}

		ans = add(ans, ans2);

	}



	return ans;



}



int main()

{



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



	int n, a, b;

	scanf("%d", &n);



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

	{

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

		adj[a].push_back(b);

		adj[b].push_back(a);

	}





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







	return 0;

}

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

using namespace std;

#define ll long long

#define sz 100100

#define MOD 1000000007



vector<int>adj[sz];



// c = 1 - white parent

// c = 0 - black parent



pair<ll, ll> dfs(int s, int p)

{

	if (adj[s].size() == 1 && adj[s][0] == p)

		return {1, 1};

	pair<ll, ll>ans = {1, 1};

	for (auto it : adj[s])

	{

		if (it == p)

			continue;

		pair<ll, ll>cur = dfs(it, s);

		ans.first = (ans.first * (cur.first + cur.second) % MOD) % MOD;

		ans.second = (ans.second * cur.first % MOD) % MOD;

	}

	return ans;

}



int main()

{

	ios::sync_with_stdio(0);

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



	int n; cin >> n;

	if (n == 1)

	{

		cout << 2;

		return 0;

	}

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

	{

		int a, b; cin >> a >> b;

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

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

	cout << (ans.first + ans.second) % MOD;

	return 0;

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

#define stdi(in) freopen(in, "r", stdin)

#define stdo(out) freopen(out, "w", stdout)

#define stdio(in, out) stdi(in); stdo(out)

#define pb push_back



using namespace std;



typedef long long ll;



const int MAX = 1e5+7;

const ll MOD = 1e9+7;



ll dp[MAX][2];

vector<int> G[MAX];



ll solve(int s, int c, int p){



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



	ll ans = 1;

	for(auto v: G[s]){

		if(v==p) continue;



		if(c==1){

			ans = (ans*solve(v,0,s))%MOD;

			continue;

		}



		ll tmp = (solve(v,0,s)+solve(v,1,s))%MOD;

		ans = (ans*tmp)%MOD;

	}



	return dp[s][c] = ans;

}



int main(){



	/*#ifndef ONLINE_JUDGE

        stdio("in", "out");

    #endif*/



	int n;

	cin>>n;

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

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

		int u,v;

		cin>>u>>v;

		G[u].pb(v);

		G[v].pb(u);

	}



	ll ans = solve(1,0,0);

	ans = (ans+solve(1,1,0))%MOD;



	cout<<ans<<'\n';



	return 0;

}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



#define mp make_pair

#define pb push_back

#define fi first

#define se second

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

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define debug(x) cerr<<#x<<" -> "<<x<<'\n'

#define debug2(x,y) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<'\n'

#define debug3(x,y,z) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<" "<<#z<<" -> "<<z<<'\n'



 

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;



using ordered_set = tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;



template<typename T>

struct CMP {

	bool operator() (const T& lhs, const T& rhs) const{

		return lhs < rhs;

	}

};



template <typename T>

T power(T a, T n){

	T res = 1;

	while(n > 0){

		if(n & 1) res = (res * a);

		a = (a * a);

		n >>= 1;

	}

	

	return res;

}



template <typename T>

T power(T a, T n, long long mm){

	T res = 1;

	while(n > 0){

		if(n & 1) res = (res * a) % mm;

		a = (a * a) % mm;

		n >>= 1;

	}

	

	return res;

}







struct S{

	ll all;

	ll black;

};



const ll N = 1e5+7;

const ll MOD = 1e9+7;

const ll INF = 2e14+7;



vector<int> edges[N];

S dp_down[N], dp_up[N];



void calc_down(int s, int p){

	

	dp_down[s] = {1, 1};

	

	for(auto v: edges[s]){

		if(v == p) continue;

		calc_down(v, s);

		dp_down[s].all = (dp_down[s].all * dp_down[v].all) % MOD;

		dp_down[s].black = (dp_down[s].black * ((dp_down[v].all - dp_down[v].black + MOD) % MOD))% MOD;

	}

	

	dp_down[s].all = (dp_down[s].all + dp_down[s].black) % MOD;

	

}







void testcase(){

	

	int n;

	cin>>n;

	int u, v;

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

		cin>>u>>v;

		edges[u].pb(v);

		edges[v].pb(u);

		

	}

	

	calc_down(1, 0);

	cout<<(dp_down[1].all)<<'\n';

	

	

}



signed main(){

	fast;

	

	int t = 1;

	//cin>>t;

	while(t--){

		testcase();

	}

	

	return 0;

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

#define stdi(in) freopen(in, "r", stdin)

#define stdo(out) freopen(out, "w", stdout)

#define stdio(in, out) stdi(in); stdo(out)

#define pb push_back



using namespace std;



typedef long long ll;



const int MAX = 1e5+7;

const ll MOD = 1e9+7;



ll dp[MAX][2];

vector<int> G[MAX];



ll solve(int s, int c, int p){



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



	ll ans = 1;

	for(auto v: G[s]){

		if(v==p) continue;



		if(c==1){

			ans = (ans*solve(v,0,s))%MOD;

			continue;

		}



		ll tmp = (solve(v,0,s)+solve(v,1,s))%MOD;

		ans = (ans*tmp)%MOD;

	}



	return dp[s][c] = ans;

}



int main(){



	/*#ifndef ONLINE_JUDGE

        stdio("in", "out");

    #endif*/

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

	int n;

	cin>>n;

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

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

		int u,v;

		cin>>u>>v;

		G[u].pb(v);

		G[v].pb(u);

	}



	ll ans = solve(1,0,0);

	ans = (ans+solve(1,1,0))%MOD;



	cout<<ans<<'\n';



	return 0;

}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



#define mp make_pair

#define pb push_back

#define fi first

#define se second

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

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define debug(x) cerr<<#x<<" -> "<<x<<'\n'

#define debug2(x,y) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<'\n'

#define debug3(x,y,z) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<" "<<#z<<" -> "<<z<<'\n'



 

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;



using ordered_set = tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;



template<typename T>

struct CMP {

	bool operator() (const T& lhs, const T& rhs) const{

		return lhs < rhs;

	}

};



template <typename T>

T power(T a, T n){

	T res = 1;

	while(n > 0){

		if(n & 1) res = (res * a);

		a = (a * a);

		n >>= 1;

	}

	

	return res;

}



template <typename T>

T power(T a, T n, long long mm){

	T res = 1;

	while(n > 0){

		if(n & 1) res = (res * a) % mm;

		a = (a * a) % mm;

		n >>= 1;

	}

	

	return res;

}







struct S{

	ll all;

	ll black;

};



const ll N = 1e5+7;

const ll MOD = 1e9+7;

const ll INF = 2e14+7;



vector<int> edges[N];

S dp_down[N], dp_up[N];



void calc_down(int s, int p){

	

	dp_down[s] = {1, 1};

	

	for(auto v: edges[s]){

		if(v == p) continue;

		calc_down(v, s);

		dp_down[s].all = (dp_down[s].all * dp_down[v].all) % MOD;

		dp_down[s].black = (dp_down[s].black * ((dp_down[v].all - dp_down[v].black + MOD) % MOD))% MOD;

	}

	

	dp_down[s].all = (dp_down[s].all + dp_down[s].black) % MOD;

	

}







void testcase(){

	

	int n;

	cin>>n;

	int u, v;

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

		cin>>u>>v;

		edges[u].pb(v);

		edges[v].pb(u);

		

	}

	

	calc_down(1, 0);

	cout<<(dp_down[1].all)<<'\n';

	

	

}



signed main(){

	fast;

	

	int t = 1;

	//cin>>t;

	while(t--){

		testcase();

	}

	

	return 0;

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



using namespace std;



#define MAXN 112345

#define ll long long

#define db(x) cerr << #x << " = " << x << endl;

#define B 1

#define W 0



set<int> G[MAXN];

int N;

int vis[MAXN][2];

ll dp[MAXN][2];

const int MOD = 1e9 + 7;



void dfs(int u, int p)

{

	G[u].erase(p);

	for (auto v : G[u])

		dfs(v, u);

}



void mul(ll &a, ll b)

{

	a = (a * b) % MOD;

}



void add(ll &a, ll b)

{

	a = (a + b) % MOD;

}



ll solve(int node, int last_color)

{

	

	if (G[node].empty())

	{

		return last_color == W ? 2:1;

	}



	ll res = 0;

	

	if (vis[node][last_color])

	{

		return dp[node][last_color];

	}

	vis[node][last_color] = 1;

	

	// PAINT BLACK	

	ll pos = 1;

	if (last_color == W)

	{

		for (auto v : G[node])

		{

			ll sub = solve(v, B);

			mul(pos, sub);

		}

		add(res, pos);

	}

	

	// PAINT WHITE

	pos = 1;

	for (auto v : G[node])

	{

		ll sub = solve(v, W);

		mul(pos, sub);

	}

	add(res, pos);

	

	dp[node][last_color] = res;

	return res;

}



int main()

{

	scanf("%d", &N);

	int u, v;

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

	{

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

		G[u].insert(v);

		G[v].insert(u);

	}

	

	dfs(1, 1);

	

	printf("%lld\n", solve(1, W));

}


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



using namespace std;

#define pb push_back

#define db(x) cerr << #x << " = " << x << endl;

#define INF 0x3f3f3f3f3f3f3f3f

#define fi first

#define se second

#define vi vector<int>

#define vll vector<ll>

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

#define pii pair<int, int>

#define pll pair<ll, ll>

#define vii vector<pii>

#define ll long long

#define ull unsigned long long

typedef long double ld;



#define MAXN 112345



const int mod = 1e9+7;



int n;

vi adj[MAXN];

int vis[MAXN][2];

ll dp[MAXN][2];



ll mul_mod(ll a, ll b)

{

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

}



ll add_mod(ll a, ll b)

{

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

}



ll solve(int u, int p_black, int pu)

{

    if (adj[u].size() == 1 && pu != 0)

    {

        return p_black ? 1:2;

    }



    if (vis[u][p_black])

        return dp[u][p_black];

    vis[u][p_black] = 1;



    ll res = 1;

    ll res_b = 1;

    for (int v : adj[u])

    {

        if (v != pu)

        {

            res = mul_mod(res, solve(v, 0, u));

            res_b = mul_mod(res_b, solve(v, 1, u));

        }

    }        



    if (!p_black)

        res = add_mod(res, res_b);



    return dp[u][p_black] = res;

}



int main()

{

    scanf("%d", &n);



    if (n == 1)

        return !printf("2\n");



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

    {

        int u, v;

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

        adj[u].pb(v);

        adj[v].pb(u);

    }



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

    

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

#include <string>

#include <bits/stdc++.h>

#include <map>





using namespace std;



using ull = unsigned long long int;

using pp = pair<ull, ull>;



int MAXN = 1e9 + 7; 

vector<pp> dp(1e5+1);





pp dfs(const vector<vector<int>>& G, int v, int p=0) {

    dp[v].first = 1;

    dp[v].second = 1;



    for (auto &&u : G[v])

    {

        if (u!=p) {

            auto u_info = dfs(G,u,v);

            dp[v].first *= (u_info.first + u_info.second) % MAXN;

            dp[v].second *= (u_info.first % MAXN);



            dp[v].first %= MAXN;

            dp[v].second %= MAXN;

        } 

    }



    return dp[v];

}





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int N;

    cin>>N;

    vector<vector<int>> G;

    G.resize(N+1);

    int x,y;

    for (size_t i = 0; i < N-1; i++)

    {

        cin>>x>>y;

        G[x].push_back(y);

        G[y].push_back(x);

    }



    auto pp = dfs(G,1,0);

    cout << (pp.first + pp.second) % MAXN << "\n";

    

}

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

#include <string>

#include <bits/stdc++.h>

#include <map>





using namespace std;



using ull = unsigned long long int;

using pp = pair<ull, ull>;



int mod = 1e9 + 7; 

// vector<pp> dp(1e5+1);





pp dfs(const vector<vector<int>>& G, int v, int p=0) {

    pp v_info{1,1};

    // dp[v].first = 1;

    // dp[v].second = 1;



    for (auto &&u : G[v])

    {

        if (u!=p) {

            auto u_info = dfs(G,u,v);

            v_info.first = (v_info.first * (u_info.first + u_info.second)) % mod;

            v_info.second = (v_info.second * u_info.first) % mod;

            // dp[v].first *= (u_info.first + u_info.second) % mod;            

            // dp[v].second *= (u_info.first % mod);

            // dp[v].first %= mod;

            // dp[v].second %= mod;

        } 

    }



    // return dp[v];

    return v_info;

}





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int N;

    cin>>N;

    vector<vector<int>> G;

    G.resize(N+1);

    int x,y;

    for (size_t i = 0; i < N-1; i++)

    {

        cin>>x>>y;

        G[x].push_back(y);

        G[y].push_back(x);

    }



    auto pp = dfs(G,1,0);

    cout << (pp.first + pp.second) % mod << "\n";

    

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

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-9, PI = acos(-1);

const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;

const ll inf = 1e18;



vector<int> adj[N];

ll mem[N][2];



ll dfs(int node, int par, int color) {

  if(mem[node][color])

    return mem[node][color];

  ll ret = 1;

  for(int it: adj[node]) {

    if(it == par) continue;

    if(color)

      ret = (ret * dfs(it, node, 0)) % MOD;

    else

      ret = ( ((ret * dfs(it, node, 0)) % MOD) + ((ret * dfs(it, node, 1))% MOD) ) % MOD;

  }

  mem[node][color] = ret;

  return ret;

}



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif

  int n, u, v;

  cin >> n;

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

    cin >> u >> v;

    adj[u].push_back(v);

    adj[v].push_back(u);

  }

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

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.542691587963281x):
#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:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;

const int mod = 1e9+7;



int n;

long long dp[N][2];

vector < int > adj[N];



void mul_self(long long & a , long long b){

    a *= b;

    a %= mod;

}

//no. of ways at node u , when u is black or white

void dfs(int u , int p){

    if(adj[u].size() == 1 && u != 1){

        dp[u][1] = 1;

        dp[u][0] = 1;

        return;

    }

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

    for(auto v : adj[u]){

        if(v == p)

            continue;

        dfs(v , u);

        mul_self(dp[u][1] , dp[v][0]);

        mul_self(dp[u][0] , (dp[v][0] + dp[v][1])%mod);

    }

}



int main(){

    scanf("%d" , &n);

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

        int u , v;

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

        adj[u].push_back(v);

        adj[v].push_back(u);

    }

    if(n == 1){

        puts("2");

        return 0;

    }

    dfs(1 , 0);

    printf("%lld\n" , (dp[1][0] + dp[1][1])%mod );

}


// Faster C++ solution for the same problem (measured speedup: 3.5079146958665466x):
#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>

using namespace std;

const int N = 1e5 + 100;

const long long mod = 1e9 + 7;

int n, par[N];

vector<int> adjList[N];

long long mem[N][2];

bool vis[N][2];



long long dp(int v, int c) {

	if (vis[v][c]) {

		return mem[v][c];

	}

	vis[v][c] = true;



	long long wans = 1;

	long long bans = c;

	for (int u : adjList[v]) {

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

		par[u] = v;

		wans = (wans * dp(u, 1)) % mod;

		bans = (bans * dp(u, 0)) % mod;

	}



	return mem[v][c] = (wans + bans) % mod;

}



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



	int a, b;

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

		cin >> a >> b;

		adjList[a].emplace_back(b);

		adjList[b].emplace_back(a);

	}



	cout << dp(1, 1) << '\n';



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5434210424158747x):
#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;

}