stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//#pragma GCC target ("avx2,sse2")

//#pragma GCC optimization ("Ofast")

//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



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

#define ll long long

#define ull unsigned long long

#define db double

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define fi first

#define se second

#define mp make_pair

#define up_b upper_bound

#define low_b lower_bound

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

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

#define endl "\n"



#define left fsdsdfoisf

#define sum dpsdfioppsf

#define assign xcvjlkdjfio

#define trie fksdfkjkfnjuiv

#define next sidlfjsfkl

#define merge sdfksdkfsldf



#define int long long



using namespace std;



void dout() {

    cerr << endl;

}

template <typename Head, typename... Tail>

void dout(Head H, Tail... T) {

    cerr << H << ' ';

    dout(T...);

}



//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair <int, int> pii;



const int N = 1e5 + 7, MOD = 1e9 + 7;

int n, dp[2][N];

vector <int> q[N];



void dfs(int v, int p) {

    int child = 0, A = 1, B = 1;

    for (auto i : q[v]) {

        if (i == p) {

            continue;

        }

        dfs(i, v);

        A = A * (dp[0][i] + dp[1][i]) % MOD;

        B = B * dp[0][i] % MOD;

        child++;

    }

    if (child == 0) {

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

        return;

    }

    dp[0][v] = A;

    dp[1][v] = B;

}



void solve(int tc) {

    // check for (int i = 0; i < n; j++)

    cin >> n;

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

        int x, y;

        cin >> x >> y;

        q[x].pb(y);

        q[y].pb(x);

    }

    dfs(1, 1);

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

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

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

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

    int tc = 1;

//    cin >> tc;

    for (int i = 0; i < tc; i++) {

        solve(i);

//        cleanup();

    }

}


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

}
// 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.418342178835255x):
#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;

}
// 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.5617137463782256x):
#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;

}
// 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.417673944322213x):
#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;

}
// Slower C++ solution:
/*

    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;

}




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

}
// 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: 1.2356468686444142x):
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

const int N=1e5+10;

const int mod=1e9+7;

const int inf=1e9;



ll dp[N][2];

bool vis[N];

vector<int> g[N];



void dfs(int u){

    if(vis[u]) return;

    vis[u]=true;

    dp[u][0]=1;

    dp[u][1]=1;

    for(auto v : g[u]){

        if(vis[v]) continue;

        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;

    }

}



int main(){

    int n;

    cin>>n;

    int a,b;

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

        cin>>a>>b;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    dfs(1);

    ll ans=(dp[1][0] + dp[1][1])%mod;

    cout<<ans<<'\n';

    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: 1.7947860062239582x):
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

const int N=1e5+10;

const int mod=1e9+7;

const int inf=1e9;



ll dp[N][2];

bool vis[N];

vector<int> g[N];



void dfs(int u){

    if(vis[u]) return;

    vis[u]=true;

    dp[u][0]=1;

    dp[u][1]=1;

    for(auto v : g[u]){

        if(vis[v]) continue;

        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;

    }

}



int main(){

    int n;

    cin>>n;

    int a,b;

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

        cin>>a>>b;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    dfs(1);

    ll ans=(dp[1][0] + dp[1][1])%mod;

    cout<<ans<<'\n';

    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: 1.2276966545968477x):
#include <bits/stdc++.h>



#define f(i,a,b) for( ll i = a; i < b ; i++ )

#define af(i,a,b) for( ll i = a; i >= b ; i--)

#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )

#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+34;

const ll inf = 1e18+7;

vi adj[MAX];

ll dp[MAX][3];



void dfs(ll u, ll parent){

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

  for(auto v: adj[u]){

    if(v == parent) continue;

    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)%mod;

  }

}



int main(){

  fastio;

  ll n,x,y;

  cin>>n;

  f(i,0,n-1){

    cin>>x>>y;

    x--;y--;

    adj[x].pb(y);

    adj[y].pb(x);

  }

  dfs(0,0);

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

  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: 1.783238262866901x):
#include <bits/stdc++.h>



#define f(i,a,b) for( ll i = a; i < b ; i++ )

#define af(i,a,b) for( ll i = a; i >= b ; i--)

#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )

#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+34;

const ll inf = 1e18+7;

vi adj[MAX];

ll dp[MAX][3];



void dfs(ll u, ll parent){

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

  for(auto v: adj[u]){

    if(v == parent) continue;

    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)%mod;

  }

}



int main(){

  fastio;

  ll n,x,y;

  cin>>n;

  f(i,0,n-1){

    cin>>x>>y;

    x--;y--;

    adj[x].pb(y);

    adj[y].pb(x);

  }

  dfs(0,0);

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

  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.4309467077293148x):
#include <bits/stdc++.h>

#define f first

#define s second

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

#define pb push_back

#define all(s) begin(s), end(s)

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

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

#define ENDL '\n'

using namespace std;

typedef long double ld;

typedef long long lli;

typedef pair<lli,lli> ii;

typedef vector<int> vi;

typedef vector<lli> vl;

typedef vector<ii> vii;

typedef vector<vi> vvi;

typedef vector<vl> vvl;

#define deb(x) cout << #x": " << (x) << endl;



const int N = 3e3+5;

const lli INF = 1e18;

const lli MOD = 1e9+7;



vi m;

vi primes(1,2);

vector<vector<ld>>nk;

void sieve(){

	m = vi(N+1,0);

	for(int i = 4; i<N; i+=2)m[i]=1;

	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;

	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);

}



void pascal(){

	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));

	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;

	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];

}



lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}



lli lcm(lli a, lli b){

	if(a<b)swap(a,b);

	lli c = gcd(a,b);

	a/=c;

	return a*b;

}



int popcount(lli x) { return __builtin_popcountll(x); }



lli poww(lli a, lli b){

	lli res =1;

	while(b){

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

		a = a*a;

		b/=2;

	}

	return res;

}



lli powm(lli a, lli b){

	lli res =1;

	while(b){

		if(b&1) res = (res * a)%MOD;

		a = (a*a)%MOD;

		b/=2;

	}

	return res;

}



bool isPrime(lli x){

	if(x==1)return 0;

	for(auto i:primes){

		if(i*i>x)return 1;

		if(x%i==0)return 0;

	}

	return 1;

}



lli SUM(lli a, lli b, lli mod=MOD){

	return (a+b+mod)%mod;

}

lli PROD(lli a, lli b, lli mod=MOD){

	a%=mod; b%=mod;

	return a*b % mod;

}

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



// ---- コーディングはここから！ ('-')7



void solve(){

	int n; cin>>n;

	vvi v(n+1);

	fore(i,0,n-1){

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

		v[a].pb(b);

		v[b].pb(a);

	}

	if(n==1){cout<<2<<ENDL;return;}

	vvl dp(n+1,vl(2,1));

	auto f=[&](auto f, int u, int pr)->void{

		for(auto i:v[u])if(i!=pr)f(f,i,u);

		for(auto i:v[u])if(i!=pr)dp[u][1]=PROD(dp[u][1],SUM(dp[i][0],dp[i][1]));

		for(auto i:v[u])if(i!=pr)dp[u][0]=PROD(dp[u][0],dp[i][1]);

	};

	f(f,1,1);



	cout<<SUM(dp[1][0],dp[1][1])<<ENDL;

}



int main(){_

	//int t; cin>>t; while(t--)

	solve();

}