Graphs/Heavy-Light Decomposition + LCA.cpp
// DFS as a first step in HLD
DFS as a first step in HLD
DFS as a first step in HLD
int DFS(int curr, int level)
{
    g[curr].level = level;
    g[curr].nodesUnder = 1;
    int sz = g[curr].adj.size();
    for(int i = 0; i < sz; i++)
    {
        g[curr].nodesUnder += DFS(g[curr].adj[i], level + 1); 
    }
    return g[curr].nodesUnder;
}
int DFS ( int curr , int level ) { g [ curr ] . level = level ; g [ curr ] . nodesUnder = 1 ; int sz = g [ curr ] . adj . size ( ) ; for ( int i = 0 ; i < sz ; i ++ ) { g [ curr ] . nodesUnder += DFS ( g [ curr ] . adj [ i ] , level + 1 ) ; } return g [ curr ] . nodesUnder ; }
DFS as a first step in HLD
DFS as a first step in HLD
// DP