比赛 |
20120708 |
评测结果 |
WWWWWWWWWW |
题目名称 |
硬币收集者 |
最终得分 |
0 |
用户昵称 |
fuhao |
运行时间 |
0.332 s |
代码语言 |
Pascal |
内存使用 |
0.90 MiB |
提交时间 |
2012-07-08 11:52:51 |
显示代码纯文本
const maxn=301; maxm=601; maxx=10001;
var
add:boolean;
f:array[0..maxm,1..2] of longint;
a:array[0..maxm,0..maxn] of longint;
fa:array[0..maxx] of longint;
link:array[0..maxn] of longint;
n,m,i,j,x,y,xx,yy,t,max:longint;
v:array[0..maxn] of boolean;
function find(k:longint):boolean;
var i:longint;
begin
for i:=1 to a[k,0] do
if not v[a[k,i]] then
begin
v[a[k,i]]:=true;
if (link[a[k,i]]=0) or (find(link[a[k,i]])) then
begin
link[a[k,i]]:=k;
exit(true);
end;
end;
exit(false);
end;
function sf(k:longint):longint;
begin
if fa[k]<>k then fa[k]:=sf(fa[k]) else exit(k);
sf:=fa[k];
end;
begin
assign(input,'coinmn.in'); reset(input);
assign(output,'coinmn.out'); rewrite(output);
readln(n);
while n<>0 do
begin
m:=0;
fillchar(a,sizeof(a),0);
fillchar(link,sizeof(link),0);
for i:=1 to n do
begin
xx:=-1; yy:=-1;
for j:=1 to 2 do
begin
read(x,y);
if x>y then //jh
begin
t:=x; x:=y; y:=t;
end;
if (xx=x) and (yy=y) then break;//panchong
add:=true;
for t:=1 to m do
if (f[t,1]=x) and (f[t,2]=y) then
begin add:=false; inc(a[t,0]); a[t,a[t,0]]:=i; break; end;
xx:=x; yy:=y;
if add then
begin
inc(m);
f[m,1]:=x; f[m,2]:=y;
inc(a[m,0]); a[m,a[m,0]]:=i;
end;
end;
end;
for i:=0 to maxx do fa[i]:=i;
j:=0; fillchar(v,sizeof(v),#0);
for i:=1 to m do
begin
fillchar(v,sizeof(v),#0);
if find(i) then
if sf(f[i,1])<>sf(f[i,2]) then
begin
fa[sf(f[i,1])]:=sf(f[i,2]);
inc(j);
end;
end;
writeln(j*2);
read(n);
end;
close(input); close(output);
end.