toj 2299 Electricity 求无向图割点
来源:互联网 发布:mac有什么网游 编辑:程序博客网 时间:2024/05/16 15:04
题意:给出一个无向图,计算去掉一个点后所能得到的最大块数
分析:dfs求出连通块的数量tot和删除每个点后能把该点所在的块分割成的块的数量s[i],那么ans就是最大的sum-s[i](我代码里的s[i]表示删除每个点后能把该点所在的块分割成的块的数量-1)
代码:
var n,m,e,t:longint; dfn,low,last,s:array[1..10000] of longint; side:array[1..40000] of record x,y,next:longint; end;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 i,x,y:longint;begin e:=0; fillchar(last,sizeof(last),0); for i:=1 to m do begin readln(x,y); add(x+1,y+1); 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 dfs(y); low[x]:=min(low[x],low[y]); if low[y]>=dfn[x] then inc(s[x]); end else low[x]:=min(low[x],dfn[y]); i:=next; end;end;procedure main;var ans,tot,i:longint;begin fillchar(dfn,sizeof(dfn),0); fillchar(low,sizeof(low),0); fillchar(s,sizeof(s),0); tot:=0; t:=0; for i:=1 to n do if dfn[i]=0 then begin inc(tot); dfs(i); dec(s[i]); end; ans:=0; for i:=1 to n do if tot+s[i]>ans then ans:=tot+s[i]; writeln(ans);end;begin readln(n,m); while n+m>0 do begin init; main; readln(n,m); end;end.
0 0
- toj 2299 Electricity 求无向图割点
- TOJ 2299. Electricity【求无向图割点】
- TOJ 2299. Electricity【求无向图割点】
- TOJ.1026 Network【求无向图割点】
- POJ 2117 Electricity(无向图割点)
- POJ 2117 Electricity(无向图割点)
- POJ 2117 Electricity(无向图割点)
- 【TOJ】2299【POJ】2117.Electricity
- POJ 2117 Electricity(无向图割点) && HDU 4587 TWO NODES
- POJ 2117 Electricity (无向图求割点)
- poj 2117 Electricity 【无向图求割点】【求去掉一个点后 图中最多的BCC数目】
- poj 2117 Electricity (无向图割点去除后最大连通分支数)
- POJ2117.Electricity——无向图的割点
- TOJ 2189. The Key Stations 【求无向图的割点】
- toj 1026 Network 无向图求割点
- 无向图求环路
- 用Tarjan算法求无向连通图割点&&割边
- POJ 1523 SPF Tarjan求无向图割点
- 虚拟机安装OSX10.11.4+编译libVLC和VLC源码
- 虚拟文件系统
- 字符串指针的问题,谢谢
- Linux内核I2C子系统详解
- 程序员可以干多少年?
- toj 2299 Electricity 求无向图割点
- Oracle 两个时间相减
- 通过MenuItem跳到别的界面以后再返回时原activity被Destroy的解决方法
- c language chaos coding
- tangowithdjango ch11
- CF 552 C. Vanya and Scales
- 快速构建Spring boot项目(功能是检测访问页面的设备)
- shell脚本的字符串截取
- MFC关于ini文件的操作方法