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

using namespace std;

const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7;

const long long OO = 1e18+25;

#define par pair<pair<int,int>, int>

#define f first

#define s second



int n, mem[N][2], u,v,vis[N][2];

vector <int> g[N];



long long dp(int ele=1, int precol=0)

{

    int &ret= mem[ele][precol];

    if(vis[ele][precol] && ret == -1) return 1;

    if(~ret) return ret;

    vis[ele][precol] = 1;

    int ans=0, ans1=1;

    if(!precol) ans =1;

    for(int e : g[ele])

    {

        vis[ele][1] ^= 2;

        ans1 = (1ll*ans1*dp(e, 0))%oo;

        vis[ele][1] ^= 2;

        if(!precol) ans = (1ll*ans*dp(e, 1))%oo;

    }

    ret = (ans+ans1)%oo;

    return ret;

}



int main()

{

    memset(mem, -1, sizeof mem);

    scanf("%d",&n);

    for(int i=0; i<n-1; i++) {scanf("%d%d",&u,&v);g[u].push_back(v);g[v].push_back(u);}

    printf("%lld",dp());

    return 0;

}

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

#include <unordered_map>

#include <unordered_set>

using namespace std;

#define endl '\n'

#define PI acos(-1)

typedef long long ll;

//	Table is the complete reverse of dp

//	Always think of the pattern (LCM, GCD)

//	Be careful of unsigned

//	double epsilon = FLT_EPSILON;

//	Think of a solution that gets TLE and optimize it

const int MOD = 1e9 + 7;

int n;

ll *dp[2];

vector<int>* ch;

int solve(int i = 0, bool col = 0, int last = n)

{

	ll &ret = dp[col][i];

	if(~ret)

		return ret;

	if((ch[i].size() == 1 && ch[i][0] == last) || ch[i].empty())

		return ret = !col + 1;

	if(col)

	{

		ret = 1;

		for(unsigned int j = 0; j < ch[i].size(); j++)

			if(ch[i][j] != last)

				ret = (ret * solve(ch[i][j], 0, i)) % MOD;

	}

	else

	{

		ll first = 1, second = 1;

		for(unsigned int j = 0; j < ch[i].size(); j++)

			if(ch[i][j] != last)

			{

				first = (first * solve(ch[i][j], 0, i)) % MOD;

				second = (second * solve(ch[i][j], 1, i)) % MOD;

			}

		ret = (first + second) % MOD;

	}

	return ret;

}

int main()

{

    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;

    ch = new vector<int>[n];

	dp[0] = new ll[n];

	dp[1] = new ll[n];

	memset(dp[0], -1, n * 8);

	memset(dp[1], -1, n * 8);

	int x, y;

	while(cin >> x >> y)

	{

		ch[x - 1].push_back(y - 1);

		ch[y - 1].push_back(x - 1);

	}

	cout << solve();

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

using namespace std;

const int N=100005;

const int mod=1000000007;

long long dp[N][2];

vector<int>e[N];

void dfs(int u,int f)

{

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

	for(int i=0;i<e[u].size();i++)

	{

		int v=e[u][i];

		if(v!=f)

		{

			dfs(v,u);

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

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

		}

	}

}

int main()

{

	int n;

	scanf("%d",&n);

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

	{

		int x,y;

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

		e[x].push_back(y);

		e[y].push_back(x);

	}

	dfs(1,0);

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

	return 0;

}


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

#include <unordered_map>

#include <unordered_set>

using namespace std;

#define endl '\n'

#define PI acos(-1)

typedef long long ll;

//	Table is the complete reverse of dp

//	Always think of the pattern (LCM, GCD)

//	Be careful of unsigned

//	double epsilon = FLT_EPSILON;

//	Think of a solution that gets TLE and optimize it

const int MOD = 1e9 + 7;

int n;

ll *dp[2];

vector<int>* ch;

int solve(int i = 0, bool col = 0, int last = n)

{

	ll &ret = dp[col][i];

	if(~ret)

		return ret;

	if((ch[i].size() == 1 && ch[i][0] == last) || ch[i].empty())

		return ret = !col + 1;

	if(col)

	{

		ret = 1;

		for(unsigned int j = 0; j < ch[i].size(); j++)

			if(ch[i][j] != last)

				ret = (ret * solve(ch[i][j], 0, i)) % MOD;

	}

	else

	{

		ll first = 1, second = 1;

		for(unsigned int j = 0; j < ch[i].size(); j++)

			if(ch[i][j] != last)

			{

				first = (first * solve(ch[i][j], 0, i)) % MOD;

				second = (second * solve(ch[i][j], 1, i)) % MOD;

			}

		ret = (first + second) % MOD;

	}

	return ret;

}

int main()

{

    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;

    ch = new vector<int>[n];

	dp[0] = new ll[n];

	dp[1] = new ll[n];

	memset(dp[0], -1, n * 8);

	memset(dp[1], -1, n * 8);

	int x, y;

	while(cin >> x >> y)

	{

		ch[x - 1].push_back(y - 1);

		ch[y - 1].push_back(x - 1);

	}

	cout << solve();

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

 

//#define int long long

//#pragma GCC optimize("Ofast")

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

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

 

 

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

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

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

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

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

#define pb push_back

#define ppb pop_back

#define s second

#define f first

 

 

using namespace std;

 

 

typedef pair < long long, long long > pll;    

typedef pair < int, int > pii;

typedef unsigned long long ull;         

typedef vector < pii > vpii;

typedef vector < int > vi;

typedef long double ldb;  

typedef long long ll;  

typedef double db;                      

 

 

const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 11;

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

const pii base = {1171, 3307}, Mod = {1e9 + 7, 1e9 + 9};

const db eps = 1e-12, pi = 3.14159265359;

const ll INF = 1e18;





int n, v, u, dp[N][2];

vi g[N];





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

	dp[v][0] = 1;

	dp[v][1] = 1;



	for (auto to : g[v])

		if (to != p) {

			dfs(to, v);

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

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

		}

}





main () {

	cin >> n;

	forn (i, 1, n - 1) {

		cin >> v >> u;

		g[v].pb(u);

		g[u].pb(v);

	}



	dfs(1);

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

}



    

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



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

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

#define F first

#define S second

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

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

#define pb push_back



using namespace std;

using ll=long long;

using pii= pair<int, int>;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

template<typename... T> void rd(T&... args) {((cin>>args), ...);}

template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}



vector<vector<int>> G;

vector<array<ll,2>> dp;

const int mod=1e9+7;

void dfs(int u,int fa){

    for(auto to:G[u]){

        if(to==fa) continue;

        dfs(to,u);

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

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

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;

    cin>>n;

    if(n==1) return cout<<2,0;

    G.resize(n+1);

    dp.resize(n+1,{1,1});

    forn(i,n-1){

        int x,y;

        cin>>x>>y;

        G[x].pb(y);

        G[y].pb(x);

    }

    for(int i=2;i<=n;i++)

        if(sz(G[i])==1) dp[i][1]=dp[i][0]=1;

    dfs(1,0);

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

    return 0;

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

using namespace std;

const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7;

const long long OO = 1e18+25;

#define par pair<pair<int,int>, int>

#define f first

#define s second



int n, mem[N][2], u,v,vis[N][2];

vector <int> g[N];



long long dp(int ele=1, int precol=0)

{

    int &ret= mem[ele][precol];

    if(vis[ele][precol] && ret == -1) return 1;

    if(~ret) return ret;

    vis[ele][precol] = 1;

    int ans=0, ans1=1;

    if(!precol) ans =1;

    for(int e : g[ele])

    {

        vis[ele][1] ^= 2;

        ans1 = (1ll*ans1*dp(e, 0))%oo;

        vis[ele][1] ^= 2;

        if(!precol) ans = (1ll*ans*dp(e, 1))%oo;

    }

    ret = (ans+ans1)%oo;

    return ret;

}



int main()

{

    memset(mem, -1, sizeof mem);

    scanf("%d",&n);

    for(int i=0; i<n-1; i++) {scanf("%d%d",&u,&v);g[u].push_back(v);g[v].push_back(u);}

    printf("%lld",dp());

    return 0;

}

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



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

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

#define F first

#define S second

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

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

#define pb push_back



using namespace std;

using ll=long long;

using pii= pair<int, int>;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

template<typename... T> void rd(T&... args) {((cin>>args), ...);}

template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}



vector<vector<int>> G;

vector<array<ll,2>> dp;

const int mod=1e9+7;

void dfs(int u,int fa){

    for(auto to:G[u]){

        if(to==fa) continue;

        dfs(to,u);

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

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

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;

    cin>>n;

    if(n==1) return cout<<2,0;

    G.resize(n+1);

    dp.resize(n+1,{1,1});

    forn(i,n-1){

        int x,y;

        cin>>x>>y;

        G[x].pb(y);

        G[y].pb(x);

    }

    for(int i=2;i<=n;i++)

        if(sz(G[i])==1) dp[i][1]=dp[i][0]=1;

    dfs(1,0);

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

    return 0;

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

using namespace std;

const int N=100005;

const int mod=1000000007;

long long dp[N][2];

vector<int>e[N];

void dfs(int u,int f)

{

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

	for(int i=0;i<e[u].size();i++)

	{

		int v=e[u][i];

		if(v!=f)

		{

			dfs(v,u);

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

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

		}

	}

}

int main()

{

	int n;

	scanf("%d",&n);

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

	{

		int x,y;

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

		e[x].push_back(y);

		e[y].push_back(x);

	}

	dfs(1,0);

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

	return 0;

}


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



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

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

#define F first

#define S second

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

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

#define pb push_back



using namespace std;

using ll=long long;

using pii= pair<int, int>;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

template<typename... T> void rd(T&... args) {((cin>>args), ...);}

template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}



vector<vector<int>> G;

vector<array<ll,2>> dp;

const int mod=1e9+7;

void dfs(int u,int fa){

    for(auto to:G[u]){

        if(to==fa) continue;

        dfs(to,u);

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

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

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;

    cin>>n;

    if(n==1) return cout<<2,0;

    G.resize(n+1);

    dp.resize(n+1,{1,1});

    forn(i,n-1){

        int x,y;

        cin>>x>>y;

        G[x].pb(y);

        G[y].pb(x);

    }

    for(int i=2;i<=n;i++)

        if(sz(G[i])==1) dp[i][1]=dp[i][0]=1;

    dfs(1,0);

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

    return 0;

}
// Slower C++ solution:
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  acos(-1)

#define EPS (1e-10)

#define endl "\n"

#define SZ(v) (int)(v.size())

#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);

typedef long long ll;

typedef long double ld;

 



 

ll MOD=1e9 + 7;

ll OO=1e15;

const int N=1e5 + 5,M=1e5 + 5;

int arr[N];

ll dp[N][3];





int n,m,k,cnt,SU,idx,len,MN,MX,T;

int l,r,mid;

int a,b,c;

int ans;



vector<int> adj[N];



ll Solve(int u,int p,bool color){

	

	ll &ret = dp[u][color];

	if(~ret)

		return ret;

	ret = 1;

	

	for(int i:adj[u]){

		if(i == p) continue;

		

		ll val = Solve(i,u,true);

		if(color)

			val += Solve(i,u,false);

		

		ret*=val;

		ret%=MOD;

	}



	return ret;

}









int main(){

	IO

	

	memset(dp,-1,sizeof dp);

	

	cin>>n;

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

		cin>>a>>b;

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	

	ll val = Solve(1,-1,0)+Solve(1,-1,1);

	val%= MOD;

	

	

	cout<<val<<endl;

	

	

}


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



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

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

#define F first

#define S second

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

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

#define pb push_back



using namespace std;

using ll=long long;

using pii= pair<int, int>;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

template<typename... T> void rd(T&... args) {((cin>>args), ...);}

template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}



vector<vector<int>> G;

vector<array<ll,2>> dp;

const int mod=1e9+7;

void dfs(int u,int fa){

    for(auto to:G[u]){

        if(to==fa) continue;

        dfs(to,u);

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

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

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;

    cin>>n;

    if(n==1) return cout<<2,0;

    G.resize(n+1);

    dp.resize(n+1,{1,1});

    forn(i,n-1){

        int x,y;

        cin>>x>>y;

        G[x].pb(y);

        G[y].pb(x);

    }

    for(int i=2;i<=n;i++)

        if(sz(G[i])==1) dp[i][1]=dp[i][0]=1;

    dfs(1,0);

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

    return 0;

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

using namespace std;

const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7;

const long long OO = 1e18+25;

#define par pair<pair<int,int>, int>

#define f first

#define s second



int n, mem[N][2], u,v,vis[N][2];

vector <int> g[N];



long long dp(int ele=1, int precol=0)

{

    int &ret= mem[ele][precol];

    if(vis[ele][precol] && ret == -1) return 1;

    if(~ret) return ret;

    vis[ele][precol] = 1;

    int ans=0, ans1=1;

    if(!precol) ans =1;

    for(int e : g[ele])

    {

        vis[ele][1] ^= 2;

        ans1 = (1ll*ans1*dp(e, 0))%oo;

        vis[ele][1] ^= 2;

        if(!precol) ans = (1ll*ans*dp(e, 1))%oo;

    }

    ret = (ans+ans1)%oo;

    return ret;

}



int main()

{

    memset(mem, -1, sizeof mem);

    scanf("%d",&n);

    for(int i=0; i<n-1; i++) {scanf("%d%d",&u,&v);g[u].push_back(v);g[v].push_back(u);}

    printf("%lld",dp());

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.137914284052224x):
/*

    if you can't see the repay

    Why not just work step by step

    rubbish is relaxed

    to ljq

*/

#include <cstdio>

#include <cstring>

#include <iostream>

#include <queue>

#include <cmath>

#include <map>

#include <stack>

#include <set>

#include <sstream>

#include <vector>

#include <stdlib.h>

#include <algorithm>

using namespace std;

typedef long long ll;

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

const int MAX_N = 100025;

int eid,p[MAX_N];

ll dp[MAX_N][2];

struct edge

{

    int v,next;

}e[MAX_N<<2];

void init()

{

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

    eid = 0;

}

void add(int u,int v)

{

    e[eid].v = v;

    e[eid].next =p[u];

    p[u] = eid++;

}

void dfs(int u,int fa)

{

    ll x = 1, y = 1;

    if(e[p[u]].next==-1&&e[p[u]].v == fa)

    {

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

        return ;

    }

    for(int i = p[u];i+1;i=e[i].next)

    {

        int v = e[i].v;

        if(v==fa) continue;

        dfs(v,u);

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

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

    }

    dp[u][0] = x,dp[u][1] = y;

}

int main()

{

    //ios::sync_with_stdio(false);

    //freopen("a.txt","r",stdin);

    //freopen("b.txt","w",stdout);

    int n,a,b;

    init();

    scanf("%d",&n);

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

    {

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

        add(a,b);

        add(b,a);

    }

    dfs(1,0);

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

    //fclose(stdin);

    //fclose(stdout);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

    return 0;

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

using namespace std;

const int N=100005;

const int mod=1000000007;

long long dp[N][2];

vector<int>e[N];

void dfs(int u,int f)

{

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

	for(int i=0;i<e[u].size();i++)

	{

		int v=e[u][i];

		if(v!=f)

		{

			dfs(v,u);

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

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

		}

	}

}

int main()

{

	int n;

	scanf("%d",&n);

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

	{

		int x,y;

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

		e[x].push_back(y);

		e[y].push_back(x);

	}

	dfs(1,0);

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

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.529535284524219x):
/*

    if you can't see the repay

    Why not just work step by step

    rubbish is relaxed

    to ljq

*/

#include <cstdio>

#include <cstring>

#include <iostream>

#include <queue>

#include <cmath>

#include <map>

#include <stack>

#include <set>

#include <sstream>

#include <vector>

#include <stdlib.h>

#include <algorithm>

using namespace std;

typedef long long ll;

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

const int MAX_N = 100025;

int eid,p[MAX_N];

ll dp[MAX_N][2];

struct edge

{

    int v,next;

}e[MAX_N<<2];

void init()

{

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

    eid = 0;

}

void add(int u,int v)

{

    e[eid].v = v;

    e[eid].next =p[u];

    p[u] = eid++;

}

void dfs(int u,int fa)

{

    ll x = 1, y = 1;

    if(e[p[u]].next==-1&&e[p[u]].v == fa)

    {

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

        return ;

    }

    for(int i = p[u];i+1;i=e[i].next)

    {

        int v = e[i].v;

        if(v==fa) continue;

        dfs(v,u);

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

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

    }

    dp[u][0] = x,dp[u][1] = y;

}

int main()

{

    //ios::sync_with_stdio(false);

    //freopen("a.txt","r",stdin);

    //freopen("b.txt","w",stdout);

    int n,a,b;

    init();

    scanf("%d",&n);

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

    {

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

        add(a,b);

        add(b,a);

    }

    dfs(1,0);

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

    //fclose(stdin);

    //fclose(stdout);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

    return 0;

}
// Slower C++ solution:
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  acos(-1)

#define EPS (1e-10)

#define endl "\n"

#define SZ(v) (int)(v.size())

#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);

typedef long long ll;

typedef long double ld;

 



 

ll MOD=1e9 + 7;

ll OO=1e15;

const int N=1e5 + 5,M=1e5 + 5;

int arr[N];

ll dp[N][3];





int n,m,k,cnt,SU,idx,len,MN,MX,T;

int l,r,mid;

int a,b,c;

int ans;



vector<int> adj[N];



ll Solve(int u,int p,bool color){

	

	ll &ret = dp[u][color];

	if(~ret)

		return ret;

	ret = 1;

	

	for(int i:adj[u]){

		if(i == p) continue;

		

		ll val = Solve(i,u,true);

		if(color)

			val += Solve(i,u,false);

		

		ret*=val;

		ret%=MOD;

	}



	return ret;

}









int main(){

	IO

	

	memset(dp,-1,sizeof dp);

	

	cin>>n;

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

		cin>>a>>b;

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	

	ll val = Solve(1,-1,0)+Solve(1,-1,1);

	val%= MOD;

	

	

	cout<<val<<endl;

	

	

}


// Faster C++ solution for the same problem (measured speedup: 4.55784317401763x):
/*

    if you can't see the repay

    Why not just work step by step

    rubbish is relaxed

    to ljq

*/

#include <cstdio>

#include <cstring>

#include <iostream>

#include <queue>

#include <cmath>

#include <map>

#include <stack>

#include <set>

#include <sstream>

#include <vector>

#include <stdlib.h>

#include <algorithm>

using namespace std;

typedef long long ll;

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

const int MAX_N = 100025;

int eid,p[MAX_N];

ll dp[MAX_N][2];

struct edge

{

    int v,next;

}e[MAX_N<<2];

void init()

{

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

    eid = 0;

}

void add(int u,int v)

{

    e[eid].v = v;

    e[eid].next =p[u];

    p[u] = eid++;

}

void dfs(int u,int fa)

{

    ll x = 1, y = 1;

    if(e[p[u]].next==-1&&e[p[u]].v == fa)

    {

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

        return ;

    }

    for(int i = p[u];i+1;i=e[i].next)

    {

        int v = e[i].v;

        if(v==fa) continue;

        dfs(v,u);

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

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

    }

    dp[u][0] = x,dp[u][1] = y;

}

int main()

{

    //ios::sync_with_stdio(false);

    //freopen("a.txt","r",stdin);

    //freopen("b.txt","w",stdout);

    int n,a,b;

    init();

    scanf("%d",&n);

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

    {

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

        add(a,b);

        add(b,a);

    }

    dfs(1,0);

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

    //fclose(stdin);

    //fclose(stdout);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

    return 0;

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

 

//#define int long long

//#pragma GCC optimize("Ofast")

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

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

 

 

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

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

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

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

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

#define pb push_back

#define ppb pop_back

#define s second

#define f first

 

 

using namespace std;

 

 

typedef pair < long long, long long > pll;    

typedef pair < int, int > pii;

typedef unsigned long long ull;         

typedef vector < pii > vpii;

typedef vector < int > vi;

typedef long double ldb;  

typedef long long ll;  

typedef double db;                      

 

 

const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 11;

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

const pii base = {1171, 3307}, Mod = {1e9 + 7, 1e9 + 9};

const db eps = 1e-12, pi = 3.14159265359;

const ll INF = 1e18;





int n, v, u, dp[N][2];

vi g[N];





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

	dp[v][0] = 1;

	dp[v][1] = 1;



	for (auto to : g[v])

		if (to != p) {

			dfs(to, v);

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

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

		}

}





main () {

	cin >> n;

	forn (i, 1, n - 1) {

		cin >> v >> u;

		g[v].pb(u);

		g[u].pb(v);

	}



	dfs(1);

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

}



    

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

#include<cstdio>

using namespace std;

typedef long long ll;

const int Maxn=1e5+5;

const int Mod=1e9+7;

struct edge{

	int v,nx;

}e[Maxn<<1];

int n,ne,f[Maxn];

ll dp[Maxn][2];

void read(int u,int v)

{	e[++ne].v=v;

	e[ne].nx=f[u];

	f[u]=ne;

}

void dfs(int u,int fa)

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

	for(int i=f[u];i;i=e[i].nx)

	{	int v=e[i].v;

		if(v==fa)continue;

		dfs(v,u);

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

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

	}

}

int main()

{	scanf("%d",&n);

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

	{	int u,v;

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

		read(u,v);read(v,u);

	}

	dfs(1,0);

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

	return 0;

}