社区讨论
明明是楼上Pas写的不对,还怪pascal不好
P2661[NOIP 2015 提高组] 信息传递参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mi4hk1iq
- 此快照首次捕获于
- 2025/11/18 19:24 4 个月前
- 此快照最后确认于
- 2025/11/18 19:24 4 个月前
CPP
program df;
var i,j,n,m,x,y,z,max,t:longint;
a,low,e,f,c:array[0..200000] of longint;
zhan,re:array[0..200000] of boolean;
function find(x:longint):longint;
begin
if f[x]<>x then f[x]:=find(f[x]);
find:=f[x];
end;
procedure dfs(x:longint);
var y:longint;
begin
inc(t);
low[x]:=t;
zhan[x]:=true;
re[x]:=true;
if (not re[a[x]]) then dfs(a[x]);
y:=find(a[x]);
if (low[x]>low[y]) and (zhan[y]) then
begin
low[x]:=low[y];
f[x]:=y;
end;
zhan[x]:=false;
end;
begin
readln(n);
for i:=1 to n do
read(a[i]);
t:=0;
for i:=1 to n do
f[i]:=i;
for i:=1 to n do
if (not re[i]) then dfs(i);
for i:=1 to n do
inc(c[find(i)]);
max:=maxlongint;
for i:=1 to n do
if (c[find(i)]<max) and (c[find(i)]>1) then
max:=c[find(i)];
writeln(max);
end.
回复
共 2 条回复,欢迎继续交流。
正在加载回复...