备用交换机 割点
来源:互联网 发布:linux安装gcc yum 编辑:程序博客网 时间:2024/05/12 03:10
题目内容
n个城市之间有通讯网络,每个城市都有通讯交换机,直接或间接与其它城市连接。因电子设备容易损坏,需给通讯点配备备用交换机。但备用交换机数量有限,不能全部配备,只能给部分重要城市配置。于是规定:如果某个城市由于交换机损坏,不仅本城市通讯中断,还造成其它城市通讯中断,则配备备用交换机。请你根据城市线路情况,计算需配备备用交换机的城市个数,及需配备备用交换机城市的编号。
分析
分析可得,如果某个城市由于交换机损坏,不仅本城市通讯中断,还造成其它城市通讯中断,那这个城市一定是无向图割点。所以就是求所有的断点。
求断点:http://www.byvoid.com/blog/biconnect/
代码
const maxe=50000; maxv=1000;type rec=record x,y,w,next:longint; flag:boolean;end;var n,m:longint; a:array[1..maxe] of rec; ls:array[1..maxv] of longint; ans:array[1..maxe] of longint; low,dfn:array[1..maxv] of longint; tot,num,ans1:longint; i,j,k:longint; root:longint;procedure dfs(r:longint);var i,j,k:longint;begin tot:=tot+1; low[r]:=tot; dfn[r]:=tot; i:=ls[r]; while i<>0 do with a[i] do begin if not flag then begin flag:=true; a[w].flag:=true; if dfn[y]=0 then begin if r=root then num:=num+1; dfs(y); if low[r]>low[y] then low[r]:=low[y]; if low[y]>=dfn[r] then ans[r]:=1; end else if low[r]>dfn[y] then low[r]:=dfn[y]; end; i:=next; end;end;procedure add(x,y:longint);begin m:=m+1; a[m].x:=x; a[m].y:=y; a[m].w:=m+1; a[m].next:=ls[x]; ls[x]:=m; m:=m+1; a[m].x:=y; a[m].y:=x; a[m].w:=m-1; a[m].next:=ls[y]; ls[y]:=m;end;begin assign(input,'gd.in'); assign(output,'gd.out'); reset(input); rewrite(output); readln(n); m:=0; num:=0; while not eof do begin readln(j,k); add(j,k); end; root:=1; dfs(1); if num>=2 then ans[root]:=1 else ans[root]:=0; ans1:=0; for i:=1 to n do if ans[i]=1 then ans1:=ans1+1; writeln(ans1); for i:=1 to n do if ans[i]=1 then writeln(i); close(input); close(output);end.
1 0
- 备用交换机(割点)
- 备用交换机 割点
- 备用交换机_cogs8_割点
- COGS 8 备用交换机 割点
- 备用交换机
- 备用交换机
- 备用交换机 双连通分量
- 备用交换机(tarjan求割点)
- 交换机割接
- 割点、割边
- 割点、割边
- 割点 割边
- 割点、割边
- 割点
- 割点
- 割点
- 割点
- 【割点】
- battery
- 剑指offer36--二叉树的深度
- 5.dup和dup2和fcntrl及标准IO
- CSS权威指南-选择相邻兄弟元素
- 第一篇博客,线性表插入数据。
- 备用交换机 割点
- java解析XML文件
- Android 查看内存使用工具 (procstats)
- 一对多的分页查询
- gdb-打开gdb的命令历史功能
- 网易大厦和他的邻居们
- 拥塞控制域流量控制
- SUSAN角点检测
- OpenMP Windows/macOS 配置指南