我遇到了一个奇怪的问题
  • 板块P1551 亲戚
  • 楼主何天承
  • 当前回复3
  • 已保存回复3
  • 发布时间2016/8/7 13:21
  • 上次更新2024/7/24 13:53:48
查看原帖
我遇到了一个奇怪的问题
1552
何天承楼主2016/8/7 13:21
program ec12;
var 
    father:array[1..5001] of longint;
    n,m,i,k,a,b,a1,b1:longint;
function getfather(u:longint):longint;
begin 
    if father[u]=u then 
    exit(u)
    else
    getfather:=getfather(father[u]);
    father[u]:=getfather;
end;
procedure union(x,y:longint);
var 
    fx,fy:longint;
begin 
    fx:=getfather(x);
    fy:=getfather(y);
    if fx<>fy then 
    father[fx]:=fy;
end;
begin 
    readln(m,n,k);
    for i:=1 to m do
    father[i]:=i;
    for i:=1 to n do
    begin 
        readln(a,b);
        if getfather(a)<>b then 
        union(a,b);
    end;
    for i:=1 to k do
    begin 
        readln(a1,b1);
        if getfather(a1)=getfather(b1) then 
        writeln('Yes')
        else
        writeln('No');
    end;
end. 

这是一个满分的程序。 但是,请注意:在读入时,我手误将“if getfather(a)<>getfather(b) then ”打成了"if getfather(a)=b then ",然后就莫名其妙的满分了,但如果改回来,就只有20分,求大神解答

2016/8/7 13:21
加载中...