Count of subtrees possible from an N-ary Tree

  
#include
#define MAX 300004
using namespace std;
  

vector graph[MAX];
int mod = 1e9 + 7;
  

int ans = 0;
  

int countSubtreesUtil(int cur, int par)
{
    
    
    int res = 1;
  
    
    for (int i = 0;
         i < graph[cur].size(); i++) {                     int v = graph[cur][i];            if (v == par)             continue;                              res = (res                * (countSubtreesUtil(                       v, cur)                   + 1))               % mod;     }             ans = (ans + res) % mod;             return res; }    void countSubtrees(int N,                    vector& adj) {          for (int i = 0; i < N - 1; i++) {         int a = adj[i].first;         int b = adj[i].second;                     graph[a].push_back(b);         graph[b].push_back(a);     }                  countSubtreesUtil(1, 1);             cout