/ Vijos / 讨论 / 问答 /

求大神帮忙 P1034家族 只过了3个点 pascal语言

var k,v,n,i,j,f,r,a1,b1,m:longint;
s:array [1..10000] of integer;
a,b:array [1..5000,1..5000] of 0..1;
f1:boolean;

begin
readln(m,n,j);
f:=0;
r:=1;
s[r]:=i;
fillchar(a,sizeof(a),0);
for i:=1 to n do
begin
readln(a1,b1);
a[a1,b1]:=1;
a[b1,a1]:=1;
end;
b:=a;
for k:=1 to j do
begin
f:=0;
r:=1;
a:=b;
f1:=false;
readln(s[r],v);
while f<r do
begin
f:=f+1;
for i:=1 to n do
if a[s[f],i]=1 then
begin
r:=r+1;
s[r]:=i;
a[s[f],s[r]]:=0;
if s[r]=v then
begin
writeln('Yes');
f1:=true;
break;
end;
end;
if s[r]=v then break;
end;
if not f1 then writeln('No');
end;
end.

3 条评论

  • @ 2017-07-18 21:43:06

    我发现我题目理解错了,谢谢指点

  • @ 2017-07-18 21:41:45

    谢谢大神!
    666

  • @ 2017-07-18 13:22:44
    var
      father:array[1..5000] of longint;
      n, m, p, i, x, y:longint;
    function getfather(u:longint):longint;
    begin
      if father[u]=u then exit(u);
      father[u]:=getfather(father[u]);
      exit(father[u])
    end;
    begin
      readln(n, m, p);
      for i:=1 to n do father[i]:=i;
      for i:=1 to m do begin
        readln(x, y);
        father[getfather(y)]:=getfather(x)
      end;
      for i:=1 to p do begin
        readln(x, y);
        if getfather(x)=getfather(y) then writeln('Yes')
        else writeln('No')
      end;
    end.
    
  • 1