POJ 1523(求割点)
来源:互联网 发布:linux c sleep 头文件 编辑:程序博客网 时间:2024/06/11 03:35
求割点入门题!
……死调一下午+晚上才发现把‘node'打成’nodes'了……
Program P1523;const maxedge=999000; maxn=10000;var edge,tail:array[1..maxedge] of longint; size:longint; head:array[1..maxn] of longint; n,i,j,ans,k:longint; b,cut:array[1..maxn] of boolean; time,root:longint; a,d,ancestor,c:array[1..maxn] of longint;procedure addedge(u,v:longint);begin inc(size); edge[size]:=v; tail[size]:=head[u]; head[u]:=size;end;function min(a,b:longint):longint;begin if a<b then exit(a) else exit(b);end;function max(a,b:longint):longint;begin if a>b then exit(a) else exit(b);end;procedure Dfs(k,father,deep:longint);var i,j,p,tot:longint;begin tot:=0; c[k]:=1; d[k]:=deep; ancestor[k]:=deep; p:=head[k]; while (p>0) do begin i:=edge[p]; if (i<>father) and (c[i]=1) then ancestor[k]:=min(ancestor[k],d[i]); if (c[i]=0) then begin dfs(i,k,deep+1); inc(tot); ancestor[k]:=min(ancestor[k],ancestor[i]); if (k=root) and (tot>=2) then cut[k]:=true; if (k<>root) and (ancestor[i]>=d[k]) then cut[k]:=true; end; p:=tail[p]; end; c[k]:=2; inc(time); a[k]:=time;end;procedure Dfs2(k:longint);var i,p:longint;begin b[k]:=true; p:=head[k]; while (p>0) do begin i:=edge[p]; if not(b[i]) then begin dfs2(i); end; p:=tail[p]; end;end;function main:boolean;var i,j,p,ans:longint;begin time:=0; main:=false; for i:=1 to maxn do if (head[i]>0) and (c[i]=0) then begin root:=i; dfs(root,0,1); end; for i:=1 to maxn do if cut[i] then begin main:=true; ans:=0; fillchar(b,sizeof(b),false); b[i]:=true; p:=head[i]; while (p>0) do begin if not(b[edge[p]]) then begin dfs2(edge[p]); inc(ans); end; p:=tail[p]; end; writeln(' SPF node ',i,' leaves ',ans,' subnets'); end;end;begin { assign(input,'p1523.in'); reset(input); } k:=1; while not seekeof do begin size:=0; fillchar(head,sizeof(head),0); fillchar(edge,sizeof(edge),0); fillchar(tail,sizeof(tail),0); fillchar(cut,sizeof(cut),false); fillchar(c,sizeof(c),0); fillchar(d,sizeof(d),0); fillchar(ancestor,sizeof(ancestor),0); read(i); if i=0 then break; read(j); while (i>0) do begin addedge(i,j); addedge(j,i); read(i); if i=0 then break; read(j); end; ans:=0; writeln('Network #',k); if not(main) then writeln(' No SPF nodes'); writeln; inc(k); end;end.
- POJ 1523(求割点)
- POJ 1523 SPF(求割点)
- poj 1523 SPF(tarjan求割点)
- 【POJ 1523】SPF(Tarjan求割点)
- POJ 1523 SPF //求割点
- POJ 1523 SPF 求割点
- POJ 1523 SPF(求割点)
- poj 1523 SPF 求割点
- poj 1523 spf 求割点
- poj 1523求割点
- poj 1523 SPF 求割点
- poj 1523 tarjan求割点
- POJ 1523 SPF【求割点】
- POJ 1523 Tarjan求割点
- POJ 1523 Tarjan求割点
- poj(1523)关节点
- POJ 1523 SPF Tarjan求割点
- POJ 1523:SPF tarjan求割点
- [EXTNET]Grid之百分比
- 文件锁和Python多进程的使用
- Compass-指南针(主要用到RotateAnimation和SensorEventListener)
- java.io.IOException: Attempted read on closed stream
- 对apk包进行odex优化的目的
- POJ 1523(求割点)
- IRP详解(2)----传输类型
- 105方时尚黑白简约风------芳满庭毕业照
- poj 1113 wall 简单的凸包
- Java通过Samba服务操作Linux共享文件
- 断开SVN连接
- 最近在写的赫夫曼树、B树、二项堆等都会用到堆排序,所以把最大堆排序和最小堆排序一次性先给大家看看
- android touch事件处理
- 尚管学习第三天笔记