【强联通分量】

本文深入探讨了算法与数据结构在软件开发中的关键作用,详细解释了它们如何提高程序效率并解决复杂问题。通过实例分析,展示了排序算法、哈希算法、动态规划等技术的实际应用,同时强调了数据结构如数组、链表、树等在不同场景下的选择与优化。此外,文章还涵盖了算法复杂度分析和数据结构设计原则,为开发者提供了一套实用的理论与实践指南。



var
v,f,yes:array[1..1000]of boolean;
dfn,low:array[1..1000]of integer;
a:array[0..1000,0..1000]of integer;
b:array [0..1000] of integer;
i,j,n,m,x,y,deep,d:integer;
stack,ln:array[1..1000]of integer;
function min(x,y:longint):integer; begin
if x>y then exit(y)
else exit(x);
end;
procedure print(x:integer);
var i:longint; begin
i:=0;fillchar(b,sizeof(b),0);
while stack[deep]<>x do
begin
inc(i);
b[i]:=stack[deep];
f[stack[deep]]:=false;
dec(deep);
end;
f[stack[deep]]:=false;
dec(deep); inc(i);b[i]:=x;
if i>1 then for x:=1 to i do yes[b[x]]:=true;
end;
procedure dfs(x:integer);
var
i:integer;
begin
inc(d); //时间
dfn[x]:=d; //规则1
low[x]:=d;
inc(deep); //栈中元素个数
stack[deep]:=x; //规则2
f[x]:=true;
for i:=1 to a[x,0] do
if dfn[a[x,i]]=0 then
begin
dfs(a[x,i]);
low[x]:=min(low[a[x,i]],low[x]); //规则3
end
else if f[a[x,i]] then
low[x]:=min(low[x],dfn[a[x,i]]);
//规则4 dfn or low 有影响吗?
if dfn[x]=low[x] then //规则5
print(x);
end;
begin
assign(input,'messagez.in'); reset(input);
assign(output,'messagez.out'); rewrite(output);
readln(n,m);
fillchar(a,sizeof(a),0);
fillchar(yes,sizeof(yes),false);
fillchar(dfn,sizeof(dfn),0);
for i:=1 to m do
begin
readln(x,y);
inc(a[x,0]);
a[x,a[x,0]]:=y;
end;
for i:=1 to n do
if dfn[i]=0 then dfs(i);
for i:=1 to n do
if yes[i] then writeln('T') else writeln('F');
close(input);close(output);
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值