比赛 20111111 评测结果 AAAAAAAAAA
题目名称 传话 最终得分 100
用户昵称 Des. 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-11-11 09:19:37
显示代码纯文本
program messagez;
var f:array[1..1000,1..1000]of boolean;
    a:array[1..1000,0..1000]of longint;
    b:Array[1..1000,1..1000]of boolean;
    q:Array[1..1000000]of longint;
    t,k,m,n,i,j:longint;
procedure spfa(p:longint);
var t,k,i,j:longint;
begin
i:=0;
j:=1;
q[1]:=p;
repeat
  inc(i);
  k:=q[i];
  for t:=1 to a[k,0] do
    if f[p,a[k,t]]=false then
      begin
        f[p,a[k,t]]:=true;
        inc(j);
        q[j]:=a[k,t];
        if f[p,p]=true then exit;
      end;
until i=j;
end;



begin
assign(input,'messagez.in');
reset(input);
assign(output,'messagez.out');
rewrite(output);
readln(n,m);
fillchar(f,sizeof(f),false);
fillchar(b,sizeof(b),false);
for t:=1 to m do
  begin
    readln(i,j);
    if b[i,j]=false then
      begin
        inc(a[i,0]);
        a[i,a[i,0]]:=j;
        b[i,j]:=true;
      end;
  end;
for t:=1 to n do
  spfa(t);
for t:=1 to n do
  if f[t,t] then writeln('T')
  else writeln('F');
close(output);
end.