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 skywalker_z at 2011-08-07 12:25:55 on Problem 1308
In Reply To:我可耻的一遍0msAC了 Posted by:hzl001 at 2011-06-06 17:19:37
LZ怎么写的这么长啊。。我的多好看!
const b:array[false..true]of string=
  (' not','');
var s:set of 0..100;
  flag,null:boolean;
  count,i,x,y:longint;
  rd,f:array[0..100]of longint;
function find(x:longint):longint;
  begin
    if f[x]=x then exit(x);
    find:=find(f[x]);
    f[x]:=find;
  end;
begin
  count:=0;
  while true do begin
    s:=[]; flag:=true; null:=false;
    fillchar(rd,sizeof(rd),0);
    for i:=1 to 100 do f[i]:=i;
    while true do begin
      read(x,y);
      if x+y=0 then break;
      if x+y<0 then halt;
      if x=y then flag:=false;
      if find(x)=find(y) then flag:=false;
      f[find(x)]:=find(y);
      inc(rd[y]); s:=s+[x]+[y];
    end;
    for i:=1 to 100 do
      if i in s then begin
        if rd[i]=0 then begin
          if null then begin
            flag:=false; break;
          end else null:=true;
        end else begin
          if rd[i]<>1 then begin
            flag:=false; break;
          end;
        end;
      end;
    if s=[] then begin flag:=true; null:=true; end;
    inc(count);
    writeln('Case ',count,' is',b[flag and null],' a tree.');
  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