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

pascal 题解

Posted by dfsatree at 2014-11-21 13:44:32 on Problem 1703
program POJ1703;
const
  maxn=100010;
Var
   f:array[0..maxn]of longint;
   v:array[0..maxn]of integer;
   t,i:longint;
   s:char;
function find(x:longint):longint;
var
   k:longint;
begin
   if(f[x]=x)then exit(x);
   k:=f[x];
   f[x]:=find(f[x]);
   v[x]:=(v[x]+v[k])and 1;
   exit(f[x]);
end;
procedure work;
var
   n,m,i,x,y:longint;
begin
   fillchar(f,sizeof(f),0);
   fillchar(v,sizeof(v),0);
   readln(n,m);
   for i:=1 to n do f[i]:=i;
   for i:=1 to m do
   begin
      readln(s,x,y);
      if(s='A')then
      begin
         if(find(x)=find(y))then
          if(v[x]=v[y])then writeln('In the same gang.')
          else writeln('In different gangs.')
         else writeln('Not sure yet.');
      end
      else
      if(find(x)<>find(y))then
      begin
         v[f[x]]:=((v[x]+v[y])+1)and 1;
         f[f[x]]:=f[y];
      end;
   end;
end;
Begin
   readln(t);
   for i:=1 to t do work;
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