割点
void targan(int u, int fa)
{
dfn[u] = low[u] = ++ti;
int flag = 0;
for (int i = head[u]; i; i = e[i].nxt)
{
int v = e[i].v;//最小回溯点
if (!dfn[v])
{
targan(v, fa);
low[u] = min(low[u], low[v]);
if (low[v] >= dfn[u] && u != fa)
{
vis[u] = 1;
}
if (u == fa)flag++;
}
low[u] = min(low[u], dfn[v]);
}
if (flag >= 2 && u == fa)vis[u] = 1;
}
割边
void targan(int u,int fa)
{
dfn[u]=low[u]=++ti;
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].v;
if(!dfn[v])
{
targan(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>dfn[u])//不是环就可以删
{
cout<<u<<" "<<v<<endl;
}
}
else if(v!=fa)low[u]=min(low[u],dfn[v]);
}
}
·