NOIP2015信息传递
来源:互联网 发布:紫色水离子淘宝店名字 编辑:程序博客网 时间:2024/05/29 19:58
Tarjan求最小生成环(注意要形成一个环而不是一个点,即size>1),这真的很模板...
var n,x,l,time,top,t,minn:longint; i :longint; dfn,low,z,size :array[0..200010] of longint; last,pre,other :array[0..200010] of longint; vis :array[0..200010] of boolean;function min(a,b:longint):longint;begin if a<b then exit(a) else exit(b);end;procedure connect(x,y:longint);begin inc(l); pre[l]:=last[x]; last[x]:=l; other[l]:=y;end;procedure dfs(x:longint);var p,q,cur:longint;begin inc(time); low[x]:=time; dfn[x]:=time; vis[x]:=true; inc(top); z[top]:=x; // q:=last[x]; while (q<>0) do begin p:=other[q]; if (dfn[p]=0) then begin dfs(p); low[x]:=min(low[x],low[p]); end else if vis[p] then low[x]:=min(low[x],dfn[p]); q:=pre[q]; end; // if (dfn[x]=low[x]) then begin cur:=-1;inc(t); while (cur<>x) do begin cur:=z[top]; dec(top); vis[cur]:=false; inc(size[t]); end; end;end;begin read(n); for i:=1 to n do begin read(x); connect(i,x); end; // for i:=1 to n do if (dfn[i]=0) then dfs(i); minn:=maxlongint; for i:=1 to t do if (size[i]<minn) and (size[i]>1) then minn:=size[i]; writeln(minn);end.——by Eirlys
转载请注明出处=w=
0 0
- [NOIP2015]信息传递
- [noip2015] 信息传递
- 【NOIP2015】信息传递
- Noip2015 D1T2信息传递
- 【NOIP2015】Day1T2 信息传递
- noip2015 信息传递
- NOIP2015信息传递
- 【NOIP2015】信息传递 dfs
- NOIP2015信息传递
- NOIP2015 信息传递
- [Noip2015] 信息传递
- [noip2015]信息传递 题解
- 【noip2015】信息传递
- [NOIP2015] 信息传递 D1 T2
- 【NOIP2015】洛谷2661 信息传递
- NOIp2015 提高组 信息传递
- [NOIP2015]Day1 T2 信息传递
- UOJ 146 【NOIP2015】信息传递
- Android 网络框架_常用的网络框架
- 设计模式之原型模式
- 在聊蜂鸣器
- 埃及分数-迭代加深
- 运算放大器带宽的讨论
- NOIP2015信息传递
- 原来Chrome自带的开发者工具还能这么用!
- 我的C/C++库理解之memchr
- bzoj 1057: [ZJOI2007]棋盘制作 (dp+悬线法)
- App研发录
- 项目分析の电源
- 调试利器console.log的用法
- mysql下如何执行sql脚本
- 【NOIP2015】神奇的幻方