toj 1026/2189 Network 求割点数量
来源:互联网 发布:美国大非农数据预测 编辑:程序博客网 时间:2024/05/29 18:58
题意:一个公司有一个网络,连接着从编号1到N共N个地方,然后给出一些边,表示哪两个地方相连。有些点一旦断开所有和它关联的边,那么图不再联通,称这样的点为“critical place”,求有多少个这样的点。
分析:直接用dfs求割点数量就好了。
代码:
var e,t,s,n:longint; side:array[1..20000] of record x,y,next:longint; end; v:array[1..100] of boolean; last,low,dfn:array[1..100] of longint;procedure add(x,y:longint);begin inc(e); side[e].x:=x; side[e].y:=y; side[e].next:=last[x]; last[x]:=e; inc(e); side[e].x:=y; side[e].y:=x; side[e].next:=last[y]; last[y]:=e;end;procedure init;var x,y:longint;begin e:=0; fillchar(last,sizeof(last),0); read(x); while x>0 do begin while not eoln do begin read(y); add(x,y); end; readln; read(x); end;end;function min(x,y:longint):longint;begin if x<y then exit(x) else exit(y);end;procedure dfs(x:longint);var i:longint;begin inc(t); dfn[x]:=t; low[x]:=t; i:=last[x]; while i>0 do with side[i] do begin if dfn[y]=0 then begin if x=1 then inc(s); dfs(y); low[x]:=min(low[x],low[y]); if low[y]>=dfn[x] then v[x]:=true; end else low[x]:=min(low[x],dfn[y]); i:=next; end;end;procedure print;var ans,i:longint;begin ans:=0; if s>1 then v[1]:=true else v[1]:=false; for i:=1 to n do if v[i] then inc(ans); writeln(ans);end;procedure main;begin fillchar(low,sizeof(low),0); fillchar(dfn,sizeof(dfn),0); fillchar(v,sizeof(v),false); s:=0; t:=0; dfs(1);end;begin readln(n); while n>0 do begin init; main; print; readln(n); end;end.
0 0
- toj 1026/2189 Network 求割点数量
- Tarjan求割点数量:Network
- POJ 1144 Network(割点数量)
- POJ 1966 Cable TV Network (用最大流求最小割点数量)
- UVA 315 - Network (求割点数模板题)
- TOJ.1026 Network【求无向图割点】
- UVA 315 求割点数
- poj1144( 求割点数)
- hrbust 1494 网络(割点数量)
- POJ 1144(求割点数)
- HDU 3313 Key Vertex 求割点数(好题)
- 求树的总结点数量,叶子节点数
- toj 1026 Network 无向图求割点
- Tarjan模板 求割点数+桥+连通分量数 来自kuangbin
- POJ 1144 Network(简单求无向图割顶数)
- POJ 1144 Network(简单求无向图割顶数)
- POJ 1144 Network(简单求无向图割顶数)
- TOJ 2189. The Key Stations 【求无向图的割点】
- JavaScript中特有的for in语句
- NIO概述
- visual_studio2013、vs2013下载
- 菜鸟入门_Python_机器学习(1)_线性可分的双月实验
- bzoj 4446: [Scoi2015]小凸玩密室
- toj 1026/2189 Network 求割点数量
- chkconfig删除某项服务
- 牛客“一站通offer” 笔试题总结
- 软件设计模式——中介者模式(Mediator)
- Java中的数组基础(一)
- ACM刷题之HDU————hide handkerchief
- 轻量级java ee企业应用实战第4版 源码下载
- Java 序列化Serializable详解
- 这次栽倒在sscanf函数上------ 看看错误的语句:int nRet = sscanf("xxx=yyy", "%s=%s", szKey, szValue);