讨论 / 额,哪错啦啊,求求求...(343题)
chip 2012-03-05 21:21:00
点我顶贴 收藏 删除
Unaccepted

测评机: Xeost[5]

得分: 90分

提交日期: 2010-10-19 13:00:00

有效耗时: 1500毫秒

测试结果1: 通过本测试点|有效耗时156ms

测试结果2: 通过本测试点|有效耗时47ms

测试结果3: 通过本测试点|有效耗时47ms

测试结果4: 通过本测试点|有效耗时156ms

测试结果5: 通过本测试点|有效耗时172ms

测试结果6: 通过本测试点|有效耗时188ms

测试结果7: 测试结果错误.错误结果为:Yes

...

通过本测试点|有效耗时234ms

测试结果9: 通过本测试点|有效耗时250ms

测试结果10: 通过本测试点|有效耗时250ms

{

rqnoj.343.home

}

program home;

var

f:array[0..10000]of longint;

s:array[1..10000]of boolean;

i,j,k,n,m,p,x,y,l:longint;

begin

readln(n,m,p);

for i:=1 to m do begin

readln(x,y);

if (f[x]<>0)or(f[y]<>0)then begin

if (f[x]<>0)and(f[y]<>0)then begin

k:=f[y];

for j:=1 to n do if f[j]=k then f[j]:=f[x];

end

else begin

if f[x]<>0 then f[y]:=f[x]

else f[x]:=f[y];

end

end

else begin

inc(l);

f[x]:=l;

f[y]:=l;

end;

end;

for i:=1 to p do begin

readln(x,y);

if (f[x]=f[y])and(f[x]<>0)and(f[y]<>0) then s[i]:=true

else s[i]:=false;

end;

for i:=1 to p do if s[i] then writeln('Yes')

else writeln('No');

readln;

end.

#1 baolong007@2012-03-04 05:41:00
回复 删除
你的编程习惯有点……不敢恭维啊……

给你发个代码吧,init我省略了,反正rqnoj上也不用!

记得要分模块写……

program tyvj1441;

var

n,m,p:longint;

f:array[0..5100]of longint;

procedure init;

begin

assign(input,'tyvj1441.in');

assign(output,'tyvj1441.out');

reset(input);

rewrite(output);

end;

procedure terminate;

begin

close(input);

close(output);

halt;

end;

function find(x:longint):longint; //找父亲模块

begin

if f[x]=x then exit(x);

f[x]:=find(f[x]);

exit(f[x]);

end;

procedure merge(a,b:longint); //合并模块

var

ra,rb:longint;

begin

ra:=find(a);

rb:=find(b);

f[ra]:=rb;

end;

procedure work;

var

i,a,b:longint;

begin

readln(n,m,p);

for i:=1 to n do

begin

f[i]:=i;

end; //初始化每人的父亲,让父亲=自己,当后面合并完了过后,没有亲戚关系的便是自己的父亲(反正就是颗树,找到根就行了)

for i:=1 to m do

begin

readln(a,b);

merge(a,b);

end;

for i:=1 to p-1 do

begin

readln(a,b);

if find(a)=find(b) then writeln('Yes')

else writeln('No');

end;

readln(a,b);

if find(a)=find(b) then write('Yes')

else write('No');

end;

begin

init;

work;

terminate;

end.

#2 Mrzhao@2012-03-05 21:21:00
回复 删除
?

#3 Mrzhao@2012-03-05 21:21:00
回复 删除
??

查看更多回复
提交回复