Calculate sum of all nodes present in a level for each level of a Tree

#include
using namespace std;
  

void add_edge(int a, int b,
              vector& tree)
{
    
    a–, b–;
  
    tree[a].push_back(b);
    tree[b].push_back(a);
}
  

void dfs(int u, int level, int par,
         int node_values[], vector& tree,
         map& sum, int& depth)
{
    
    depth = max(depth, level);
  
    
    
    sum[level] += node_values[u];
  
    for (int child : tree[u]) {
  
        if (child == par)
            continue;
  
        
        dfs(child, level + 1, u, node_values,
            tree, sum, depth);
    }
}
  

void getSum(int node_values[],
            vector& tree)
{
    
    int depth = 0;
  
    
    map sum;
  
    dfs(0, 0,
        -1, node_values,
        tree, sum, depth);
  
    
    for (int i = 0; i