noip2015 信息传递
来源:互联网 发布:联想yoga11s 编程 编辑:程序博客网 时间:2024/06/05 10:10
const maxn=200000;var fa,son,q:array[0..maxn] of longint; vis:array[0..maxn] of boolean; l,r,i,n,x,ans:longint;function min(a,b:longint):longint;begin if a<b then exit(a) else exit(b);end;procedure dfs(n,k,st:longint);begin if (n=k) and (st>1) then begin ans:=min(ans,st-1); exit; end; vis[n]:=false; dfs(fa[n],k,st+1);end;begin fillchar(vis,sizeof(vis),true); fillchar(son,sizeof(son),0); readln(n); for i:=1 to n do begin read(fa[i]); inc(son[fa[i]]); end; l:=1;r:=1; for i:=1 to n do if son[i]=0 then begin q[r]:=i; inc(r); end; while l<=r do begin x:=q[l]; vis[x]:=false; dec(son[fa[x]]); if son[fa[x]]=0 then begin q[r]:=fa[x]; inc(r); end; inc(l); end; ans:=maxlongint; for i:=1 to n do if vis[i] then dfs(i,i,1); writeln(ans);end.
1 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】信息传递
- iptables & ebtables 默认表名
- java反射Method中的如何调用任意方法,即invoke()的使用
- Android产品研发(七)-->Apk热修复
- 搭建微信公共平台的本地测试
- activemq 控制面板里的 Number Of Pending Messages、 Messages Enqueued、Messages Dequeued含义
- noip2015 信息传递
- Nginx多Server反向代理配置
- Android a应用打开b应用
- 临时
- Fragment的添加步骤
- C#获取路径总结
- Spark之Scala学习之路(三)
- 微信xml解析
- Redis系列~主从复制(十八)