Language: C++

#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
#define mp make_pair
#define pb push_back
using namespace std;

const lli mod = 1e9 + 7;

lli power(lli x, lli y) {
    x %= mod;
    if (y == 0) return 1;
    return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2)) % mod;
    // return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2));
}

vector <long long int> primeNumbers;

void SieveOfEratosthenes(int n){
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++){
      if (prime[p]){
        primeNumbers.push_back(p);
      }
    }        
}

#define MAXN 100005
vector < vector < int> > v(MAXN);
int d[MAXN];
int visit[MAXN];
long long int dp[MAXN][2];
//dp[i][0] is for black
//dp[i][1] is for white

void dfs(int vertex){
  visit[vertex] = 1;
  for(int i = 0;i<v[vertex].size();i++){
    int node = v[vertex][i];
    if(visit[node] == 1);
    else{
      // temp = false;
      visit[node] = 1;
      dfs(node);
      visit[node] = 0;
    }
  }
      // dp[vertex][0] += dp[node][1];
      // dp[vertex][0] %= mod;
      // dp[vertex][1] += dp[node][0] + dp[node][1];
      // dp[vertex][1] %= mod;

  for(int i = 0;i<v[vertex].size();i++){
    int node = v[vertex][i];
    if(visit[node] == 1);
    else{
      visit[node] = 1;
      dp[vertex][0] *= dp[node][1];
      dp[vertex][0] %= mod;
      dp[vertex][1] *= (dp[node][0] + dp[node][1])%mod;
      dp[vertex][1] %= mod;
    }
  }

}

void pre(){
}

void solve(){
  int n;
  cin>>n;
  for(int i = 0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i = 0;i<=n;i++){
    dp[i][0] = 1;
    dp[i][1] = 1;
  }

  int root = 1;
  dfs(root);
  int ans = dp[root][0]%mod + dp[root][1]%mod;
  ans %= mod;
  

  // for(int i = 1;i<=n;i++){
  //   cout<<dp[i][0]<<' '<<dp[i][1]<<endl;
  // }



  cout<<ans;



















}
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 
  int t;
  // cin>>t;
  // scanf("%d",&t);
  t = 1;
  pre();
  while(t--){
    // cout<<
    solve();
 
    if(t>0){
      cout<<endl;
      // printf("\n");
    } 
  }
 
 
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
  return 0;
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:48:3: error: reference to 'visit' is ambiguous
   48 |   visit[vertex] = 1;
      |   ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:5:
/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:42:5: note:                 'int visit [100005]'
   42 | int visit[MAXN];
      |     ^~~~~
a.cc:51:8: error: reference to 'visit' is ambiguous
   51 |     if(visit[node] == 1);
      |        ^~~~~
/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:42:5: note:                 'int visit [100005]'
   42 | int visit[MAXN];
      |     ^~~~~
a.cc:54:7: error: reference to 'visit' is ambiguous
   54 |       visit[node] = 1;
      |       ^~~~~
/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:42:5: note:                 'int visit [100005]'
   42 | int visit[MAXN];
      |     ^~~~~
a.cc:56:7: error: reference to 'visit' is ambiguous
   56 |       visit[node] = 0;
      |       ^~~~~
/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:42:5: note:                 'int visit [100005]'
   42 | int visit[MAXN];
      |     ^~~~~
a.cc:66:8: error: reference to 'visit' is ambiguous
   66 |     if(visit[node] == 1);
      |        ^~~~~
/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:42:5: note:                 'int visit [100005]'
   42 | int visit[MAXN];
      |     ^~~~~
a.cc:68:7: error: reference to 'visit' is ambiguous
   68 |       visit[node] = 1;
      |       ^~~~~
/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:42:5: note:                 'int visit [100005]'
   42 | int visit[MAXN];
      |     ^~~~~