比赛 |
20111111 |
评测结果 |
AAAAAAAAAA |
题目名称 |
传话 |
最终得分 |
100 |
用户昵称 |
lizhe |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-11 10:06:17 |
显示代码纯文本
program messagez;
var
i,l,n,m,a,b,time,t:longint;
dfn,low,stack:array[1..1000]of longint;
flag:array[1..1000]of boolean;
vet,map:array[1..1000,0..1000]of longint;
procedure init;
begin
assign(input,'messagez.in');
reset(input);
assign(output,'messagez.out');
rewrite(output);
read(n,m);
for i:=1 to m do
begin
read(a,b);
inc(map[a,0]);
map[a,map[a,0]]:=b
end;
fillchar(flag,sizeof(flag),true)
end;
procedure tarjan(u:longint);
var
i,v:longint;
begin
inc(time);
dfn[u]:=time;
low[u]:=time;
stack[time]:=u;
flag[u]:=false;
for i:=1 to map[u,0] do
begin
v:=map[u,i];
if dfn[v]=0 then
begin
tarjan(v);
if low[u]>low[v] then low[u]:=low[v]
end
else if flag[v]=false then
begin
if low[u]>dfn[v] then
low[u]:=dfn[v]
end
end;
if dfn[u]=low[u] then
begin
inc(t);
repeat
v:=stack[time];
flag[v]:=true;
inc(vet[t,0]);
vet[t,vet[t,0]]:=v;
dec(time)
until u=v;
end
end;
procedure main;
begin
for l:=1 to n do
if dfn[l]=0 then
tarjan(l);
fillchar(flag,sizeof(flag),true);
for i:=1 to t do
if vet[i,0]>1 then
for l:=1 to vet[i,0] do
flag[vet[i,l]]:=false;
end;
procedure print;
begin
for i:=1 to n do
if flag[i] then writeln('F')
else writeln('T');
close(input);
close(output)
end;
begin
init;
main;
print
end.