tarjan求割点如下两写法
1
void cutp(int u, int fa){
dfn[u] = low[u] = ++num;
int child = 0;
for(int i = head[u];i;i = edge[i].nxt) {
int v = edge[i].v;
if(!dfn[v]) {
child++;
cutp(v, u);
low[u] = min(low[u], low[v]);
if((u == fa && child > 1) || (u != fa && low[v] >= dfn[u]))
iscut[u] = 1;
}
else low[u] = min(low[u], dfn[v]);
}
}
2
void dfs(int u, int fa) {
low[u] = num[u] = ++dfn;
int child = 0;
for(int i =head[u]; i ; i = edge[i].nxt) {
int v = edge[i].v;
if(!num[v]) {
if(u == fa) child++;
dfs(v, u);
low[u] = min(low[v], low[u]);
if(low[v] >= num[u] && u != fa) {
iscut[u] =1;
}
}
else if(num[v] < num[u] && v != fa)
low[u] = min(low[u], num[v]);
}
if( u == fa && child >= 2) {
iscut[fa] = 1;
}
}