Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我可耻的一遍0msAC了

Posted by hzl001 at 2011-06-06 17:19:37 on Problem 1308
一遍0msAC!!!
这么ws的模拟竟然一遍AC激动啊
代码:
program poj1308;
const
  maxn=100;

var
  b,bj,dd:array[1..maxn] of longint;
  x,y,t,s,d,bb:longint;

function fa(x:longint):boolean;
begin
  if dd[x]=1 then exit(false);
  if b[x]<>0 then
  begin
    dd[x]:=1;
    fa:=fa(b[x]);
  end
  else exit(true);
end;

begin
  read(x,y); t:=0;
  while (x=0) and (y=0) do
  begin
    inc(t);
    writeln('Case ',t,' is a tree.');
    read(x,y);
  end;
  while (x<>-1) and (y<>-1) do
  begin
    inc(t);
    fillchar(b,sizeof(b),0);
    fillchar(bj,sizeof(bj),0);
    s:=0; d:=0; bb:=0;
    while (x<>0) and (y<>0) do
    begin
      inc(s);
      if bj[x]=0 then
      begin
        bj[x]:=1; inc(d);
      end;
      if bj[y]=0 then
      begin
        bj[y]:=1; inc(d);
      end;

      if b[y]=0 then b[y]:=x
      else
      begin
        bb:=1;
      end;

       fillchar(dd,sizeof(dd),0);
      if not(fa(y)) then
      begin
        bb:=1;
      end;
      read(x,y);
    end;
    if s+1<>d then bb:=1;
    if bb=1 then
      writeln('Case ',t,' is not a tree.')
    else
      writeln('Case ',t,' is a tree.');
    read(x,y);
    while (x=0) and (y=0) do
    begin
      inc(t);
      writeln('Case ',t,' is a tree.');
      read(x,y);
    end;
  end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator