- 家族
- 2014-11-05 22:37:56 @
var i,j,n,m,p,a,b,l:longint;
x:array[0..6001] of longint;
gx:array[0..8000,0..8000] of boolean;
begin
readln(n,m,p);
for i:=1 to n do
for j:=1 to n do
gx[i,j]:=false;
for i:=1 to m do
begin
readln(a,b);
gx[a,b]:=true;
gx[b,a]:=true;
end;
for i:=1 to n do
x[i]:=i;
for l:=1 to 8 do
for i:=1 to n do
for j:=1 to n do
if (gx[i,j]) and (x[j]>x[i]) then
x[j]:=x[i]
else if (gx[i,j]) then x[i]:=x[j];
for i:=1 to p do
begin
readln(a,b);
if x[a]=x[b] then writeln('Yes')
else writeln('No');
end;
end.
这样也都是AC= =虽说8是凑出来的 不过也可以啊。。
测试数据 #0: Accepted, time = 0 ms, mem = 63476 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 63480 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 63476 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 63476 KiB, score = 10
测试数据 #4: Accepted, time = 31 ms, mem = 63476 KiB, score = 10
测试数据 #5: Accepted, time = 156 ms, mem = 63476 KiB, score = 10
测试数据 #6: Accepted, time = 343 ms, mem = 63480 KiB, score = 10
测试数据 #7: Accepted, time = 593 ms, mem = 63476 KiB, score = 10
测试数据 #8: Accepted, time = 968 ms, mem = 63480 KiB, score = 10
测试数据 #9: Accepted, time = 937 ms, mem = 63480 KiB, score = 10
Accepted, time = 3028 ms, mem = 63480 KiB, score = 100
3 条评论
-
Lytning LV 8 @ 2014-11-06 11:19:23
你可以给数据范围加一个零,再试试比较你的方法和并查集。。
-
2014-11-06 09:28:26@
感觉并查集很方便啊,速度相对又比较快,代码又好写。
-
2014-11-05 22:39:04@
是因为时间太长 易超时吗?
- 1