记录编号 |
39305 |
评测结果 |
AWWWWWWWWE |
题目名称 |
硬币收集者 |
最终得分 |
10 |
用户昵称 |
fuhao |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.314 s |
提交时间 |
2012-07-08 17:46:36 |
内存使用 |
0.90 MiB |
显示代码纯文本
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,opt:longint;
v:array[0..maxn] of boolean;
function sf(k:longint):longint;
begin
if fa[k]<>k then fa[k]:=sf(fa[k]) else exit(k);
sf:=fa[k];
end;
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) and (sf(f[a[k,i],1])<>sf(f[a[k,i],2]))
or find(link[a[k,i]]) then
begin
link[a[k,i]]:=k;
fa[sf(f[a[k,i],1])]:=sf(f[a[k,i],2]);
exit(true);
end;
end;
exit(false);
end;
begin
assign(input,'coinmn.in'); reset(input);
assign(output,'coinmn.out'); rewrite(output);
readln(n);
while n<>0 do
begin
m:=0; inc(opt);
fillchar(a,sizeof(a),0);
fillchar(link,sizeof(link),0);
for i:=1 to n do
for j:=1 to 2 do
begin
read(x,y);
if x>y then
begin
t:=x; x:=y; y:=t;
end;
add:=true;
for t:=1 to m do
if (f[t,1]=x) and (f[t,2]=y) then
begin add:=false; inc(a[i,0]); a[i,a[i,0]]:=t; break; end;
if add then
begin
inc(m);
inc(a[i,0]); a[i,a[i,0]]:=m;
f[m,1]:=x; f[m,2]:=y;
end;
end;
for i:=0 to maxx do fa[i]:=i;
j:=0; fillchar(v,sizeof(v),#0);
for i:=1 to n do
begin
fillchar(v,sizeof(v),#0);
if find(i) then inc(j);
end;
writeln(j*2);
read(n);
end;
close(input); close(output);
end.