直接看代码
std::vector<int> d; inline bool cmp(int a,int b){ return dfn[a]<dfn[b]; } inline void build(){ std::sort(d.begin(),d.end(),cmp); for(int i=d.size()-2;~i;i--) d.push_back(LCA(d[i],d[i+1])); std::sort(d.begin(),d.end(),cmp); d.erase(std::unique(d.begin(),d.end()),d.end()); top=0; for(int i=0;i<(int)d.size();i++){ int u=d[i]; while(top&&low[sta[top]]<dfn[u])top--; if(top)fa[u]=sta[top]; sta[++top]=u; } }