hihocoder-1183(割点,桥模板)

我就不晓得这个坑B题目为什么上面这个可以过

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=500000+10;
const int maxv=1000000+10;

struct my{
       int v;
       int next;
};

struct lmjer{
       int x,y;
};

int adj[maxn],fa,root,dfn[maxn],low[maxn],dfsn,topp,tope;
bool cutpoint[maxv];
lmjer cutedge[maxn];
my bian[maxv*2];

bool cmp(const lmjer a,const lmjer b){
     if(a.x==b.x) return a.y<b.y;
     else return a.x<b.x;
}

void myinsert(int u,int v){
     bian[++fa].v=v;
     bian[fa].next=adj[u];
     adj[u]=fa;
}

void dfs(int x,int in_edge){
     low[x]=dfn[x]=++dfsn;
     int child=0;
     for (int i=adj[x];i;i=bian[i].next){
        int v=bian[i].v;
        if(!dfn[v]){
            dfs(v,i);
            low[x]=min(low[x],low[v]);
            if(low[v]>dfn[x]){
               int x=bian[i].v;
               int y=bian[i^1].v;
               cutedge[++tope].x=min(x,y);
               cutedge[tope].y=max(x,y);
            }
            if(low[v]>=dfn[x]){
                child++;
                if(x!=root || child>1){
                    cutpoint[x]=1;
                }
            }
        }
        else if(i!=(in_edge^1)){
            low[x]=min(low[x],dfn[v]);
        }
     }
}

int main(){
    fa=1;
    int n,m;
    int u,v;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        myinsert(u,v);
        myinsert(v,u);
    }
    for (int i=1;i<=n;i++){
        if(!dfn[i]){
            root=i;
            dfs(i,0);;
        }
    }
    int sum=0;
    for (int i=1;i<=n;i++){
        if(cutpoint[i]) {sum++;printf("%d ",i);}
    }
    if(sum==0) printf("Null");
    printf("\n");
    sort(cutedge+1,cutedge+1+tope,cmp);
    for (int i=1;i<=tope;i++){
        printf("%d %d\n",cutedge[i].x,cutedge[i].y);
    }
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=500000+10;
const int maxv=1000000+10;

struct my{
       int v;
       int next;
};

struct lmjer{
       int x,y;
};

int adj[maxn],fa,root,dfn[maxn],low[maxn],dfsn,cutpoint[maxn],topp,tope;
lmjer cutedge[maxn];
my bian[maxv*2];

bool cmp(const lmjer a,const lmjer b){
     if(a.x==b.x) return a.y<b.y;
     else return a.x<b.x;
}

void myinsert(int u,int v){
     bian[++fa].v=v;
     bian[fa].next=adj[u];
     adj[u]=fa;
}

void dfs(int x,int in_edge){
     low[x]=dfn[x]=++dfsn;
     int child=0;
     for (int i=adj[x];i;i=bian[i].next){
        int v=bian[i].v;
        if(!dfn[v]){
            dfs(v,i);
            low[x]=min(low[x],low[v]);
            if(low[v]>dfn[x]){
               int x=bian[i].v;
               int y=bian[i^1].v;
               cutedge[++tope].x=min(x,y);
               cutedge[tope].y=max(x,y);
            }
            if(low[v]>=dfn[x]){
                child++;
                if(x!=root || child>1){
                    cutpoint[++topp]=x;
                }
            }
        }
        else if(i!=(in_edge^1)){
            low[x]=min(low[x],dfn[v]);
        }
     }
}

int main(){
    fa=1;
    int n,m;
    int u,v;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        myinsert(u,v);
        myinsert(v,u);
    }
    for (int i=1;i<=n;i++){
        if(!dfn[i]){
            root=i;
            dfs(i,0);;
        }
    }
    if(cutpoint==0) printf("Null");
    else {
     sort(cutpoint+1,cutpoint+1+topp);
     for (int i=1;i<=topp;i++){
        printf("%d ",cutpoint[i]);
     }
    }
    printf("\n");
    sort(cutedge+1,cutedge+1+tope,cmp);
    for (int i=1;i<=tope;i++){
        printf("%d %d\n",cutedge[i].x,cutedge[i].y);
    }
return 0;
}

 

posted @ 2018-07-28 16:38  lmjer  阅读(110)  评论(0编辑  收藏  举报