Error404 Blog


Main Page


Pre and Post Numbers



    void dfs(int u,int par,int level){
        startTime[u]=++tim; 
        for(int v: g[u]){
            if(v!=par){
                dfs(v,u,level+1);
            }
        }
        endTime[u]=tim;
    }
    int count()
    {
        //number of nodes at cur level that is descendent of pth par is counted.
        int ans=(upper_bound(all(lvl[cur]),endTime[pthpar])-lower_bound(all(lvl[cur]),startTime[pthpar]));
    }