【模板】图的割点
2016-04-30 12:47
357 查看
lrj
dfn:发现时间
low:子树中可以追溯到最早的节点的发现时间
dfn:发现时间
low:子树中可以追溯到最早的节点的发现时间
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int M=501000; const int N=101000; struct E {int to,nxt;}edge[M*2]; int low ,dfn ,Time=0; int idx ,tot=1; bool iscut ; int n,m,ans; void addedge(int from,int to){ edge[tot].to=to;edge[tot].nxt=idx[from];idx[from]=tot++; } void dfs(int x,int fa){ int child=0; dfn[x]=low[x]=++Time; for(int t=idx[x];t;t=edge[t].nxt){ E e=edge[t]; if(!dfn[e.to]){ child++; dfs(e.to,x); low[x]=min(low[e.to],low[x]); if(low[e.to]>=dfn[x]) iscut[x]=1; } else if(e.to!=fa) low[x]=min(low[x],dfn[e.to]); } if(fa==-1 && child==1) iscut[x]=0; } int main(){ // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); addedge(x,y);addedge(y,x); } dfs(1,-1); for(int i=1;i<=n;i++) if(iscut[i]) ans++; printf("%d\n",ans); return 0; }
相关文章推荐
- Scala学习笔记-基本数据类型
- linux 娱乐软件和游戏安装方法目录
- 数据库复习(一)
- iOS-Undefined symbols for architecture x86_64-- 调适萤石摄像头驱动程序--萤石开放平台
- 14软件工程第八次作业
- 系统分析师成长之路
- Sqoop在导入MySQL数据时遇到Timestamp列为0000-00-00 00:00:00报错
- 【模板】费用流
- 2016.4.30
- Android滚轮时间选择控件(可扩展自定义)
- 使用ToolBar改变旋转图表的颜色
- iptables
- 【模板】KMP
- HDU-4035 Maze (概率DP&&树形DP)
- 32-3Sum
- 解读Google分布式锁服务
- 数学算法那些事
- 【模板】RMQ
- Intellij IDEA 14.1.4安装详细图解与注册方法
- 解读Google分布式锁服务