记录编号 33146 评测结果 RWWWRWWWEE
题目名称 游历校园 最终得分 0
用户昵称 GravatarCzb。 是否通过 未通过
代码语言 Pascal 运行时间 2.282 s
提交时间 2011-11-09 16:13:24 内存使用 1.15 MiB
显示代码纯文本
program fdfdf;
var n,i,j,m,x,y,f1,f2,tot1,ans:longint;
    f,num,oddn,c:array[1..100000] of longint;
function dfs(v:longint):longint;
begin
    if v<>f[v] then f[v]:=dfs(f[v]);
    dfs:=f[v];
end;
begin
assign(input,'sent.in');assign(output,'sent.out');
reset(input); rewrite(output);
readln(n);
readln(m);
fillchar(c,sizeof(c),0);
for i:=1 to n do f[i]:=i;
for i:=1 to m do
begin
readln(x,y);
if x=y then continue;
f1:=dfs(x); f2:=dfs(y);
if f1<>f2 then
f[f1]:=y;
inc(c[x]); inc(c[y]);
end;
fillchar(num,sizeof(num),0) ;
fillchar(oddn,sizeof(oddn),0);
for i:=1 to n do
begin
f1:=dfs(i);
inc(num[f1]);
if odd(c[i]) then inc(oddn[f1]);
end;
tot1:=0; ans:=0;
for i:=1 to n do
if num[i] >1 then
begin
if oddn[i]>2 then
ans:=ans+(oddn[i]-2) div 2;
inc(tot1);
end;
writeln(ans+tot1-1);
close(input); close(output);
end.