哪个写法更好??
  • 板块灌水区
  • 楼主StrFaith
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/11/22 15:06
  • 上次更新2024/11/22 17:53:04
查看原帖
哪个写法更好??
970752
StrFaith楼主2024/11/22 15:06

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;
    }
}
2024/11/22 15:06
加载中...