tarjan
来源:互联网 发布:matlab for mac安装 编辑:程序博客网 时间:2024/06/05 14:32
http://kmplayer.iteye.com/blog/604532
var next,last,z,tov,low,dfn:array[1..1000000] of longint; vis,zz:array[1..1000000] of boolean; tot,n,m,i,x,y,time,zd,ans:longint;procedure insert(x,y:longint);begin inc(tot); tov[tot]:=y; next[tot]:=last[x]; last[x]:=tot;end;function min(x,y:longint):longint;begin if x<y then exit(x); exit(y);end;procedure tarjan(x:longint);var i,y,t:longint;begin inc(time); dfn[x]:=time; low[x]:=time; inc(zd); z[zd]:=x; zz[x]:=true; i:=last[x]; while i<>0 do begin y:=tov[i]; if vis[y] then begin vis[y]:=false; tarjan(y); low[x]:=min(low[x],low[y]); end else if zz[y] then low[x]:=min(low[x],dfn[y]); i:=next[i]; end; if dfn[x]=low[x] then begin t:=0; repeat zz[z[zd]]:=false; inc(t); dec(zd); until z[zd+1]=x; inc(ans,t*(t-1)div 2); end;end;begin readln(n,m); for i:=1 to m do begin readln(x,y); insert(x,y); end; fillchar(vis,sizeof(vis),true); for i:=1 to n do if vis[i] then begin vis[i]:=false; tarjan(i); end; writeln(ans);end.
阅读全文
0 0
- tarjan
- Tarjan
- Tarjan
- tarjan
- tarjan
- tarjan
- Tarjan
- Tarjan
- Tarjan
- Tarjan
- Tarjan
- tarjan
- Tarjan
- Tarjan
- Tarjan
- tarjan
- tarjan算法
- hdoj1269 Tarjan
- BZOJ4539: [Hnoi2016]树
- cannot change version web module 3.0
- gensim 英文文本相似度
- 第十一周项目二:操作用邻接表存储的图
- Git的基础介绍和使用
- tarjan
- 2017年薪酬最高的编程语言
- 我的 10 年自学编程之路
- android第一步,雀氏纸尿裤
- 前端团队协作一点见解
- Python运维基础(3)程序大练习(ATM)
- 几个学校作业
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- 最佳旅游路线