Language: C++

//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define forn(i,n) for(int i = 0; i < n; ++i)
int INF = 1e9+7;
ll inf = 1e18+7;
int MOD = 1e9+7;

void add_self(auto &a, auto b){
	a += b;
	if(a >= MOD){
		a -= MOD;
	}
}

void sub_self(auto &a, auto b){
	a -= b;
	if(a < 0)	a += MOD;
}

void max_self(auto &a, auto b){
	if(b > a)	a = b;
}

void min_self(auto &a, auto b){
	if(b < a)	a = b;
}

void mul_self(auto &a, auto b){
	ll temp = a*b;
	a = (int) temp%MOD;
}

void topsort(int i, v<vi>& graph, vb& visit, stack<int>& res){
	visit[i] = true;
	
	for(int x : graph[i]){
		if(!visit[x])
		topsort(x,graph,visit,res);
	}
	res.push(i);
}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

const int N = 100010;
int dp[N][2];
vb visit(N,0);

int color(int i,bool c,int p, v<vi>& tree){
	visit[i] = true;
	if(dp[i][c] != -1)	return dp[i][c];
	if(tree[i].size() == 1 && tree[i][0] == p)	{
		dp[i][c] = 1;
		return 1;
	}
	int ans = 1;
	for(int child : tree[i]){
		if(child == p) continue;
		int temp = 0;
		if (c == 1){
			add_self(temp, color(child,0,i,tree));
		}
		else{
			add_self(temp, color(child,0,i,tree));
			add_self(temp, color(child,1,i,tree));
		}
		mul_self(ans, temp);
	}
	//cout << i << "  " << c << "  " << ans << endl;
	dp[i][c] = ans;
	return ans;
}

void solve(){
	for(int i = 0; i < N; ++i){
		dp[i][0] = -1;
		dp[i][1] = -1;
	}
	
	int n;
	scanf("%d",&n);
	v<vi> tree(n);
	forn(i,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		a -= 1;
		b -= 1;
		tree[a].pb(b);
		tree[b].pb(a);
	}
	int ans = 0;
	for(int i =0 ;i < n; ++i){
		if (visit[i] == false){
			add_self(ans, (color(i,0,-1,tree) + color(i,1,-1,tree))%MOD);
		}
	}
	printf("%d\n", ans);
}	



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Compiler output:
a.cc:28:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   28 | void add_self(auto &a, auto b){
      |               ^~~~
a.cc:28:24: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   28 | void add_self(auto &a, auto b){
      |                        ^~~~
a.cc:35:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   35 | void sub_self(auto &a, auto b){
      |               ^~~~
a.cc:35:24: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   35 | void sub_self(auto &a, auto b){
      |                        ^~~~
a.cc:40:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   40 | void max_self(auto &a, auto b){
      |               ^~~~
a.cc:40:24: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   40 | void max_self(auto &a, auto b){
      |                        ^~~~
a.cc:44:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   44 | void min_self(auto &a, auto b){
      |               ^~~~
a.cc:44:24: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   44 | void min_self(auto &a, auto b){
      |                        ^~~~
a.cc:48:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   48 | void mul_self(auto &a, auto b){
      |               ^~~~
a.cc:48:24: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   48 | void mul_self(auto &a, auto b){
      |                        ^~~~
a.cc: In function 'int color(int, bool, int, std::vector<std::vector<int> >&)':
a.cc:78:9: error: reference to 'visit' is ambiguous
   78 |         visit[i] = true;
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:8:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:75:4: note:                 'vb visit'
   75 | vb visit(N,0);
      |    ^~~~~
a.cc: In function 'void solve()':
a.cc:121:21: error: reference to 'visit' is ambiguous
  121 |                 if (visit[i] == false){
      |                     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:75:4: note:                 'vb visit'
   75 | vb visit(N,0);
      |    ^~~~~