poj1144 割点模板
2016-11-15 17:13
176 查看
tarjan求割点(low[p]>=dfn[x]) 的模板题,注意对dfs序列根节点情况的单独考虑(必须访问至少两次)
——by Eirlys
var n,ans,l,x,y :longint; time,son :longint; last,low,dfn :array[0..110] of longint; vis,flag :array[0..110] of boolean; pre,other :array[0..20010] of longint; i :longint; procedure connect(x,y:longint); begin inc(l); pre[l]:=last[x]; last[x]:=l; other[l]:=y; end; function min(a,b:longint):longint; begin if a<b then exit(a) else exit(b); end; procedure dfs(x:longint); var p,q:longint; begin inc(time); low[x]:=time; dfn[x]:=time; vis[x]:=true; // q:=last[x]; while (q<>0) do begin p:=other[q]; if dfn[p]=0 then begin dfs(p); low[x]:=min(low[x],low[p]); if (low[p]>=dfn[x]) and (x<>1) then flag[x]:=true else if (x=1) and (low[p]>=dfn[x]) then inc(son); end else if vis[p] then low[x]:=min(low[x],dfn[p]); q:=pre[q]; end; end; begin read(n); while (n<>0) do begin l:=0;ans:=0;son:=0;time:=0; fillchar(last,sizeof(last),0); fillchar(dfn,sizeof(dfn),0); fillchar(low,sizeof(low),0); fillchar(vis,sizeof(vis),false); fillchar(flag,sizeof(flag),false); read(x); while (x<>0) do begin while not eoln do begin read(y); connect(x,y); connect(y,x); end; read(x); end; for i:=1 to n do if dfn[i]=0 then dfs(i); if (son>1) then inc(ans); for i:=1 to n do if flag[i] then inc(ans); writeln(ans); read(n); end; end.
——by Eirlys
相关文章推荐
- poj 1144 Network 图的割顶判断模板
- poj1144(求割点---kuangbin的模板)
- poj 1144 Network (割点模板)
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
- POJ 1144 Network (割点,两种模板)
- Poj 1144 Zoj 1311 求割点 模板
- POJ 1144 Network(无向图的割顶和桥模板题)
- 【模板】【POJ1144】Network——tarjan求割点
- POJ 1144 Network (割点模板题)
- [poj 1144]割项模板
- [poj1144]Network(求割点模板)
- 【POJ1144】Network(割点)(模板)
- POJ 1144 Network Tarjan 求无向图的割点的个数 Tarjan 模板题
- poj 1144 Network(模板题)(Tarjan 关节点的朴素算法)
- poj 1144 Network (tarjan割点模板)
- POJ 1144 Network 图论 求割点模板
- POJ 1144 Network 求桥的模板题
- poj 1144 Network 图的割顶判断模板
- poj 1144 Network【无向图求割顶模板题】
- [POJ 3461] Oulipo & KMP模板