zoukankan      html  css  js  c++  java
  • 洛谷 P3388 【模板】割点(割顶)

    题目

    思路

    tarjan求割点
    不会的戳(不知道好不好自己康康吧)

    (Code)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #define min_(a,b) a>b?b:a;
    #define MAXN 100010
    int n,m,cnt,id;
    int head[MAXN];
    int dfn[MAXN],low[MAXN];
    bool cut[MAXN];
    struct Edge{
    	int next,to;
    }edge[200001];//无向图
    inline int read(){
    	int x=0;bool f=0;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    	return f?-x:x;
    }
    void add_edge(int from,int to){
    	edge[++cnt].to=to,edge[cnt].next=head[from],head[from]=cnt;
    }
    void tarjan(int u,int father){
    	dfn[u]=low[u]=++id;
    	int ch=0;
    	for(int i=head[u];i;i=edge[i].next){
    		int x=edge[i].to;
    		if(!dfn[x]){
    			tarjan(x,father);
    			low[u]=min_(low[u],low[x]);
    			if(low[x]>=dfn[u]&&u!=father) cut[u]=1;
    			if(u==father) ch++;
    		}
    		low[u]=min_(low[u],dfn[x]);
    	}
    	if(ch>=2&&u==father) cut[u]=1;
    }
    
    int main(){
    	n=read(),m=read();
    	int u,v;
    	for(int i=1;i<=m;++i){
    		u=read(),v=read();
    		add_edge(u,v),add_edge(v,u);
    	}
    	for(int i=1;i<=n;++i){
    		if(!dfn[i]) tarjan(i,i);
    	}
    	int tot=0;
    	for(int i=1;i<=n;++i){
    		if(cut[i]) tot++;
    	}
    	printf("%d
    ",tot);
    	for(int i=1;i<=n;++i){
    		if(cut[i]) printf("%d ",i);
    	}
    	puts("");
    	return 0;
    }
    
  • 相关阅读:
    js 变量的声明能提升 初始化不会提升
    老公教我写分页
    响应式布局
    闭包优缺点
    正则表达式验证邮箱格式
    DDL表和库管理语言
    DML数据库操作语言
    python实现求第K小
    硬币凑数
    MySQL学习的表单定义
  • 原文地址:https://www.cnblogs.com/poi-bolg-poi/p/11215857.html
Copyright © 2011-2022 走看看