http://acm.hdu.edu.cn/showproblem.php?pid=3018

题解:

 

  1. /* 一笔画问题: 每条边过且只过一次,问至少要画几笔才能全部边都经过(不考虑鼓励的点)  
  2.    图有多个集合构成  集合有两种  
  3.    一种为含奇数点的  一种为只含偶数点的 
  4.    对于含奇数点的     笔画数=奇数点个数/2  
  5.    对于只含偶数点的   存在欧拉回路  笔画数=1 
  6.    对于整张图  则  ans=总奇数点/2+只含偶数点的集合个数 
/*
*@Author:   STZG
*@Language: C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int pre[N];
int in[N],odd[N];
bool vis[N];
char str;
int find(int x){return pre[x]==x?x:pre[x]=find(pre[x]);}
void marge(int u,int v){
    int tu=find(u);
    int tv=find(v);
    if(tu!=tv){
        pre[tu]=tv;
    }
}
void init(){
    for(int i=1;i<=n;i++){
       pre[i]=i;
    }
    ans=0;
    memset(in,0,sizeof(in));
    memset(odd,0,sizeof(odd));
    memset(vis,0,sizeof(vis));
}
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    while(~scanf("%d%d",&n,&m)){
        init();
        for(int i=1;i<=m;i++){
            scanf("%d%d",&u,&v);
            marge(u,v);
            in[u]++;
            in[v]++;
        }
        vector<int>v;
        for(int i=1;i<=n;i++){
            int fa=find(i);
            if(!vis[fa]){
                v.push_back(fa);
                vis[fa]=1;
                //ans++;
            }
            if(in[i]&1)
                odd[fa]++;
        }
        for(int i=0;i<v.size();i++){
            k=v[i];
            if(in[k]==0)continue;
            if(odd[k]==0)ans++;
            else ans+=odd[k]/2;
        }
        cout<<ans<<endl;
    }
    //}

#ifdef DEBUG
	printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Hello world!" << endl;
    return 0;
}