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

using namespace std;

typedef long long ll;



const int mod = 1e9 + 7, mxN = 1e5 + 5, mxC = 2;

int N;

vector<int> adj[mxN];

ll dp[mxN][mxC];



ll rec(int v, int p, int pcol) {

	if (dp[v][pcol] != -1)

		return dp[v][pcol];

	ll tot = 0, ways = 1;

	if (pcol == 0) {

		for (auto it : adj[v]) {

			if (it != p) {

				ways = (ways * rec(it, v, 1)) % mod;

			}

		}

		tot = ways;

	}

	ways = 1;

	for (auto it : adj[v]) {

		if (it != p) {

			ways = (ways * rec(it, v, 0)) % mod;

		}

	}

	tot = (tot + ways) % mod;

	return dp[v][pcol] = tot;

}



int main() {

	ios_base::sync_with_stdio(false);



	cin >> N;

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

		int x, y;

		cin >> x >> y;

		adj[x].push_back(y);

		adj[y].push_back(x);

	}

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

	ll answer = rec(1, 0, 0);

	cout << answer;



	return 0;

}

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

using namespace std;

typedef long long ll;



const int mxN = 1e5 + 5, mod = 1e9 + 7;

int N;

vector<int> adj[mxN];

int dp[mxN][2];



int rec(int u, int p, int pc) {

	if (dp[u][pc] != -1) {

		return dp[u][pc];

	}

	ll tot = 0, ways = 1;

	if (pc == 0) {

		for (int v : adj[u]) {

			if (v == p) {

				continue;

			}

			ways = (ways * rec(v, u, 1)) % mod;

		}

		tot = ways;

	}

	ways = 1;

	for (int v : adj[u]) {

		if (v == p) {

			continue;

		}

		ways = (ways * rec(v, u, 0)) % mod;

	}

	tot = (tot + ways) % mod;

	return dp[u][pc] = tot;

}



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	

	cin >> N;

	int x, y;

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

		cin >> x >> y;

		x--, y--;

		adj[x].push_back(y);

		adj[y].push_back(x);

	}

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

	int ans = rec(0, -1, 0);

	cout << ans;

	

	return 0;

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

#include <queue>

#define mod 1000000007



using namespace std;

int n,i,x,y;

struct nodS

{

    int parent=0;

    bool viz=false;

    long long dpa=1, dpb=1;

    vector <int> vecini;

} nod[100005];

struct poz

{

    int parent, id;

    poz(int id, int parent)

    {

        this->id=id;

        this->parent=parent;

    }

};

queue <poz> q;

void rez(int poz)

{

    for(auto it : nod[poz].vecini)

    {

        if(it!=nod[poz].parent)

        {

            rez(it);

            nod[poz].dpa*=(nod[it].dpa+nod[it].dpb);

            nod[poz].dpa%=mod;

            nod[poz].dpb*=nod[it].dpa;

            nod[poz].dpb%=mod;

        }

    }

}

int main()

{

    cin>>n;

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

    {

        cin>>x>>y;

        nod[x].vecini.push_back(y);

        nod[y].vecini.push_back(x);

    }

    for(auto it : nod[1].vecini)

    {

        q.push(poz(it, 1));

    }





    while(!q.empty())

    {

        poz curr=q.front();

        nod[curr.id].parent=curr.parent;

        for(auto it : nod[curr.id].vecini)

            if(it!=curr.parent)

            {

                q.push(poz(it, curr.id));

            }



        q.pop();

    }



    /*

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

    {

        cout<<nod[i].parent<<' ';

    }

    */



    rez(1);

    /*

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

    {

        cout<<nod[i].dpa<<' '<<nod[i].dpb<<'\n';

    }

    */



    cout<<(nod[1].dpa+nod[1].dpb)%mod;

    return 0;

}


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

using namespace std;

#define endl '\n'

const int mod=1000000007;

int n;

vector<int> g[100010];

int dp[100010][2];

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

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

	if(~an)return an;

	an=1;

	for(auto x:g[u]){

		if(x==par)continue;

		int ans=0;

		if(col!=1){

			ans+=dfs(x,u,1);

			if(ans>=mod)ans-=mod;

		}

		ans+=dfs(x,u,0);

		if(ans>=mod)ans-=mod;

		an=(1LL*an*ans)%mod;

	}

	return an;

}



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	memset(dp,-1,sizeof dp);



	cin>>n;

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

		int u,v;

		cin>>u>>v;

		g[u].push_back(v);

		g[v].push_back(u);

	}

	g[0].push_back(1);

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





	return 0;

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

#include <queue>

#define mod 1000000007



using namespace std;

int n,i,x,y;

struct nodS

{

    int parent=0;

    bool viz=false;

    long long dpa=1, dpb=1;

    vector <int> vecini;

} nod[100005];

struct poz

{

    int parent, id;

    poz(int id, int parent)

    {

        this->id=id;

        this->parent=parent;

    }

};

queue <poz> q;

void rez(int poz)

{

    for(auto it : nod[poz].vecini)

    {

        if(it!=nod[poz].parent)

        {

            rez(it);

            nod[poz].dpa*=(nod[it].dpa+nod[it].dpb);

            nod[poz].dpa%=mod;

            nod[poz].dpb*=nod[it].dpa;

            nod[poz].dpb%=mod;

        }

    }

}

int main()

{

    cin>>n;

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

    {

        cin>>x>>y;

        nod[x].vecini.push_back(y);

        nod[y].vecini.push_back(x);

    }

    for(auto it : nod[1].vecini)

    {

        q.push(poz(it, 1));

    }





    while(!q.empty())

    {

        poz curr=q.front();

        nod[curr.id].parent=curr.parent;

        for(auto it : nod[curr.id].vecini)

            if(it!=curr.parent)

            {

                q.push(poz(it, curr.id));

            }



        q.pop();

    }



    /*

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

    {

        cout<<nod[i].parent<<' ';

    }

    */



    rez(1);

    /*

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

    {

        cout<<nod[i].dpa<<' '<<nod[i].dpb<<'\n';

    }

    */



    cout<<(nod[1].dpa+nod[1].dpb)%mod;

    return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>

#define fastio() ios_base::sync_with_stdio(false);

#define rmod(x, y) ((((x)%(y))+(y))%(y))

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;

typedef long double ld;

template<typename T, typename R = null_type, typename C = less<T>>

tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){

	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();

}





const int maxn = 1e5+5, mod = 1e9+7;



int add(int a, int b){return (a+b)%mod;}

int mul(ll a, ll b){return (a*b)%mod;}

int n, x, y, dp[maxn][2];

vector<int> vs[maxn];



int dfs(int v, int p, bool col){

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

	int ret = dp[v][col];

	ret = 1;

	for(int e: vs[v]) if (e != p){

		int t = dfs(e, v, 1);

		if (col) t = add(t, dfs(e, v, 0));

		ret = mul(ret, t);

	}

	return dp[v][col] = ret;

}



int main(){

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

	scanf("%d", &n);

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

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

		vs[--x].push_back(--y);

		vs[y].push_back(x);

	}

	dfs(0, -1, 1);

	dfs(0, -1, 0);

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

	return 0;

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

#include<map>

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<cstdio>

#include<string>

#include<vector>

#include<random>

#include<cstdlib>

#include<cstring>

#include<iomanip>

#include<iostream>

#include<algorithm>

#define endl "\n"

#define fi first

#define se second

#define db double

#define gcd __gcd

#define pb push_back

#define mp make_pair

#define lowbit(x) (x & (-x))

#define PII  pair<int, int> 

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

#define debug(x) cout << #x << " = " << x << endl

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

#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)

#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }

template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }

typedef long long ll;

typedef unsigned long long ull;

const db eps = 1e-9;

const db PI = acos(-1);

const int inf = 0x3f3f3f3f;

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

const int maxn = (int)1e5 + 5;//remember to modify it, No RE or MLE

const ll INF = 0x3f3f3f3f3f3f3f3f;

using namespace std;



int n;

vector<int> G[maxn];

ll dp[maxn][2];



void mul(ll &a, ll b){

	a = (a * b) % mod;

}



void dfs(int u, int fa){

	int len = G[u].size();

	rep(i, 0, len - 1){

		int v = G[u][i];

		if(v == fa) continue;

		dfs(v, u);

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

		mul(dp[u][1], dp[v][1] + dp[v][0]);

	}

}



int main()

{

	scanf("%d", &n);

	rep(i, 1, n - 1){

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

		G[u].pb(v);

		G[v].pb(u);

	}

	rep(i, 1, n) dp[i][0] = dp[i][1] = 1;

	dfs(1, 0);

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

	return 0;

}

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

#define f first

#define s second

#define pb push_back

#define ENDL '\n'

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

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

#define deb(a) cout << #a << ": "  << a << ENDL

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

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



using namespace std;



typedef long long lli;

typedef long double ld;

typedef pair<lli, lli> ii;



const int MAXN = 1e5 + 5;



lli dp[2][MAXN];



lli MOD = 1e9 + 7;



vector<vector<lli>> graph;



lli n;



lli dfs(int u, int pr, int color) {

    lli &ans = dp[color][u];

    if(ans != -1) return ans;

    ans = 1;

    for(auto it : graph[u]) {

        if(it == pr) continue;

        lli cur = dfs(it, u, 0);

        if(color == 0) cur = (cur + dfs(it, u, 1)) % MOD;

        ans = (ans * cur) % MOD;

    }

    return ans;

}



int main()

{   _

    fore(i, 0, 2) fore(j, 0, MAXN) dp[i][j] = -1;

    lli u, v; cin >> n;

    graph.resize(n);

    fore(i, 1, n) {

        cin >> u >> v;

        graph[u - 1].pb(v - 1);

        graph[v - 1].pb(u - 1);

    }

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

    return 0;

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

#include <queue>

#define mod 1000000007



using namespace std;

int n,i,x,y;

struct nodS

{

    int parent=0;

    bool viz=false;

    long long dpa=1, dpb=1;

    vector <int> vecini;

} nod[100005];

struct poz

{

    int parent, id;

    poz(int id, int parent)

    {

        this->id=id;

        this->parent=parent;

    }

};

queue <poz> q;

void rez(int poz)

{

    for(auto it : nod[poz].vecini)

    {

        if(it!=nod[poz].parent)

        {

            rez(it);

            nod[poz].dpa*=(nod[it].dpa+nod[it].dpb);

            nod[poz].dpa%=mod;

            nod[poz].dpb*=nod[it].dpa;

            nod[poz].dpb%=mod;

        }

    }

}

int main()

{

    cin>>n;

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

    {

        cin>>x>>y;

        nod[x].vecini.push_back(y);

        nod[y].vecini.push_back(x);

    }

    for(auto it : nod[1].vecini)

    {

        q.push(poz(it, 1));

    }





    while(!q.empty())

    {

        poz curr=q.front();

        nod[curr.id].parent=curr.parent;

        for(auto it : nod[curr.id].vecini)

            if(it!=curr.parent)

            {

                q.push(poz(it, curr.id));

            }



        q.pop();

    }



    /*

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

    {

        cout<<nod[i].parent<<' ';

    }

    */



    rez(1);

    /*

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

    {

        cout<<nod[i].dpa<<' '<<nod[i].dpb<<'\n';

    }

    */



    cout<<(nod[1].dpa+nod[1].dpb)%mod;

    return 0;

}


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

#define f first

#define s second

#define pb push_back

#define ENDL '\n'

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

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

#define deb(a) cout << #a << ": "  << a << ENDL

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

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



using namespace std;



typedef long long lli;

typedef long double ld;

typedef pair<lli, lli> ii;



const int MAXN = 1e5 + 5;



lli dp[2][MAXN];



lli MOD = 1e9 + 7;



vector<vector<lli>> graph;



lli n;



lli dfs(int u, int pr, int color) {

    lli &ans = dp[color][u];

    if(ans != -1) return ans;

    ans = 1;

    for(auto it : graph[u]) {

        if(it == pr) continue;

        lli cur = dfs(it, u, 0);

        if(color == 0) cur = (cur + dfs(it, u, 1)) % MOD;

        ans = (ans * cur) % MOD;

    }

    return ans;

}



int main()

{   _

    fore(i, 0, 2) fore(j, 0, MAXN) dp[i][j] = -1;

    lli u, v; cin >> n;

    graph.resize(n);

    fore(i, 1, n) {

        cin >> u >> v;

        graph[u - 1].pb(v - 1);

        graph[v - 1].pb(u - 1);

    }

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

    return 0;

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

using namespace std;

#define endl '\n'

const int mod=1000000007;

int n;

vector<int> g[100010];

int dp[100010][2];

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

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

	if(~an)return an;

	an=1;

	for(auto x:g[u]){

		if(x==par)continue;

		int ans=0;

		if(col!=1){

			ans+=dfs(x,u,1);

			if(ans>=mod)ans-=mod;

		}

		ans+=dfs(x,u,0);

		if(ans>=mod)ans-=mod;

		an=(1LL*an*ans)%mod;

	}

	return an;

}



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	memset(dp,-1,sizeof dp);



	cin>>n;

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

		int u,v;

		cin>>u>>v;

		g[u].push_back(v);

		g[v].push_back(u);

	}

	g[0].push_back(1);

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





	return 0;

}

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

#define f first

#define s second

#define pb push_back

#define ENDL '\n'

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

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

#define deb(a) cout << #a << ": "  << a << ENDL

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

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



using namespace std;



typedef long long lli;

typedef long double ld;

typedef pair<lli, lli> ii;



const int MAXN = 1e5 + 5;



lli dp[2][MAXN];



lli MOD = 1e9 + 7;



vector<vector<lli>> graph;



lli n;



lli dfs(int u, int pr, int color) {

    lli &ans = dp[color][u];

    if(ans != -1) return ans;

    ans = 1;

    for(auto it : graph[u]) {

        if(it == pr) continue;

        lli cur = dfs(it, u, 0);

        if(color == 0) cur = (cur + dfs(it, u, 1)) % MOD;

        ans = (ans * cur) % MOD;

    }

    return ans;

}



int main()

{   _

    fore(i, 0, 2) fore(j, 0, MAXN) dp[i][j] = -1;

    lli u, v; cin >> n;

    graph.resize(n);

    fore(i, 1, n) {

        cin >> u >> v;

        graph[u - 1].pb(v - 1);

        graph[v - 1].pb(u - 1);

    }

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

    return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#define fastio() ios_base::sync_with_stdio(false);

#define rmod(x, y) ((((x)%(y))+(y))%(y))

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;

typedef long double ld;

template<typename T, typename R = null_type, typename C = less<T>>

tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){

	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();

}





const int maxn = 1e5+5, mod = 1e9+7;



int add(int a, int b){return (a+b)%mod;}

int mul(ll a, ll b){return (a*b)%mod;}

int n, x, y, dp[maxn][2];

vector<int> vs[maxn];



int dfs(int v, int p, bool col){

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

	int ret = dp[v][col];

	ret = 1;

	for(int e: vs[v]) if (e != p){

		int t = dfs(e, v, 1);

		if (col) t = add(t, dfs(e, v, 0));

		ret = mul(ret, t);

	}

	return dp[v][col] = ret;

}



int main(){

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

	scanf("%d", &n);

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

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

		vs[--x].push_back(--y);

		vs[y].push_back(x);

	}

	dfs(0, -1, 1);

	dfs(0, -1, 0);

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

	return 0;

}


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

#define f first

#define s second

#define pb push_back

#define ENDL '\n'

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

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

#define deb(a) cout << #a << ": "  << a << ENDL

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

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



using namespace std;



typedef long long lli;

typedef long double ld;

typedef pair<lli, lli> ii;



const int MAXN = 1e5 + 5;



lli dp[2][MAXN];



lli MOD = 1e9 + 7;



vector<vector<lli>> graph;



lli n;



lli dfs(int u, int pr, int color) {

    lli &ans = dp[color][u];

    if(ans != -1) return ans;

    ans = 1;

    for(auto it : graph[u]) {

        if(it == pr) continue;

        lli cur = dfs(it, u, 0);

        if(color == 0) cur = (cur + dfs(it, u, 1)) % MOD;

        ans = (ans * cur) % MOD;

    }

    return ans;

}



int main()

{   _

    fore(i, 0, 2) fore(j, 0, MAXN) dp[i][j] = -1;

    lli u, v; cin >> n;

    graph.resize(n);

    fore(i, 1, n) {

        cin >> u >> v;

        graph[u - 1].pb(v - 1);

        graph[v - 1].pb(u - 1);

    }

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

    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.240510185111901x):
#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;

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

}