#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int p[100005];
int rank[100005];
int vis[100005];
int mark[100005];
int degree[100005];
void make_set(int i)
{
p[i]=i;
rank[i]=0;
}
int find_set(int i)
{
if(i!=p[i])
p[i]=find_set(p[i]);
return p[i];
}
int Union(int x,int y)
{
x=find_set(x);
y=find_set(y);
if(x==y)
return 0;
if(rank[x]<rank[y])
p[x]=y;
else
{
p[y]=x;
if(rank[x]==rank[y])
rank[x]++;
}
return 1;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i;
memset(degree,0,sizeof(degree));
memset(rank,0,sizeof(rank));
memset(vis,0,sizeof(vis));
memset(mark,0,sizeof(mark));
memset(p,0,sizeof(p));
for(i=0;i<m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
if(!vis[a])
{
vis[a]=1;
make_set(a);
}
if(!vis[b])
{
vis[b]=1;
make_set(b);
}
degree[a]++;
degree[b]++;
Union(a,b);
}
int res=0;
for(i=1;i<=n;i++)
{
if(vis[i]&°ree[i]%2==1)
{
if(mark[find_set(i)]==0)
mark[find_set(i)]=1;
res++;
}
}
res=res/2;
for(i=1;i<=n;i++)
{
if(vis[i]&&mark[i]==0&&p[i]==i)
res++;
}
printf("%d\n",res);
}
return 0;
}
hdu3108
最新推荐文章于 2017-12-02 16:20:10 发布