Problem p03175 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<lli, lli>
#define vi vector<lli>
#define mii map<lli, lli>
#define pqb priority_queue<lli>
#define pqs priority_queue<lli, vi, greater<lli>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \
  lli x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void SS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
const int N = 1e5 + 5;
vector<int> graph[N];
int u, v;
int n;
int dp[N][2];
int add(lli a, lli b) { return ((a % mod) + (b % mod)) % mod; }
int mul(lli a, lli b) { return ((a % mod) * (b % mod)) % mod; }
void dfs(int node, int par) {
  dp[node][1] = 1;
  dp[node][0] = 1;
  for (lli i : graph[node]) {
    if (i == par)
      continue;
    dfs(i, node);
    dp[node][0] = mul(dp[node][0], add(dp[i][1], dp[i][0]));
    dp[node][1] = mul(dp[node][1], dp[i][0]);
  }
}
void solve() {
  cin >> n;
  for (int i = 0, u, v; i < n - 1; i++) {
    cin >> u >> v;
    graph[u].pb(v);
    graph[v].pb(u);
  }
  dfs(1, 0);
  cout << add(dp[1][0], dp[1][1]) << endl;
}
int main() {
  SS();
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<lli, lli>
#define vi vector<lli>
#define mii map<lli, lli>
#define pqb priority_queue<lli>
#define pqs priority_queue<lli, vi, greater<lli>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \
  lli x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void SS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 1e5 + 5;
vector<int> graph[N];
int u, v;
int n;
int dp[N][2];
int add(lli a, lli b) { return ((a % mod) + (b % mod)) % mod; }
int mul(lli a, lli b) { return ((a % mod) * (b % mod)) % mod; }
void dfs(int node, int par) {
  dp[node][1] = 1;
  dp[node][0] = 1;
  for (lli i : graph[node]) {
    if (i == par)
      continue;
    dfs(i, node);
    dp[node][0] = mul(dp[node][0], add(dp[i][1], dp[i][0]));
    dp[node][1] = mul(dp[node][1], dp[i][0]);
  }
}
void solve() {
  cin >> n;
  for (int i = 0, u, v; i < n - 1; i++) {
    cin >> u >> v;
    graph[u].pb(v);
    graph[v].pb(u);
  }
  dfs(1, 0);
  cout << add(dp[1][0], dp[1][1]) << endl;
}
int main() {
  SS();
  solve();
  return 0;
}