比赛 20111111 评测结果 AAAAAAAAAA
题目名称 传话 最终得分 100
用户昵称 reamb 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-11-11 09:36:17
显示代码纯文本
program messagez;
var
  d,i,t,time,n,m,x,y,j:longint;
  stack,dfn,low,a:array[1..1000]of longint;
  instack:array[1..1000]of boolean;
  map:array[1..1000,1..1000]of boolean;
  bz:array[1..1000]of boolean;
function min(a,b:longint):longint;
begin
  if a<b then
    exit(a)
  else
    exit(b)
end;
procedure tarjan(u:longint);
var
  v:longint;
begin
  inc(time);
  dfn[u]:=time;
  low[u]:=time;
  inc(t);
  stack[t]:=u;
  instack[u]:=true;
  for v:=1 to n do
  begin
    if map[u,v] then
    begin
      if dfn[v]=0 then
      begin
        tarjan(v);
        low[u]:=min(low[u],low[v])
      end
      else
        if instack[v] then
          low[u]:=min(low[u],dfn[v])
    end
  end;
  if low[u]=dfn[u] then
  begin
    d:=0;
    while low[stack[t]]<>dfn[stack[t]] do
    begin
      inc(d);
      a[d]:=stack[t];
      instack[stack[t]]:=false;
      dec(t)
    end;
    instack[stack[t]]:=false;
    inc(d);
    a[d]:=stack[t];
    dec(t);
    if d=1 then
    begin
      bz[a[1]]:=false
    end
    else
    begin
      for i:=1 to d do
        bz[a[i]]:=true
    end
  end;
end;
begin
  assign (input,'messagez.in');
  reset (input);
  assign (output,'messagez.out');
  rewrite (output);
    readln (n,m);
    for i:=1 to n do
      instack[i]:=false;
    for i:=1 to n do
      for j:=1 to n do
        map[i,j]:=false;
    for i:=1 to m do
    begin
      readln (x,y);
      map[x,y]:=true
    end;
    for i:=1 to n do
    begin
      if dfn[i]=0 then
        tarjan(i)
    end;
    for i:=1 to n do
      if bz[i] then
        writeln ('T')
      else
        writeln ('F');
  close (input);
  close (output)
end.