E
1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 #include<vector>
5 using namespace std;
6 const int N=1010;
7 vector<int>g[N];
8 int f[N];
9 int n,m;
10 int mark[N];
11
12 int Find(int x)
13 {
14 return (x==f[x])?x:(f[x]=Find(f[x]));
15 }
16
17 int main()
18 {
19 // freopen("1.in","r",stdin);
20 // freopen("1.out","w",stdout);
21 while (~scanf("%d%d",&n,&m)) {
22 for (int i=0;i<n;i++) {
23 f[i]=i;
24 g[i].clear();
25 }
26 while (m--) {
27 int x,y;
28 scanf("%d%d",&x,&y);
29 g[x].push_back(y);
30 g[y].push_back(x);
31 int xx=Find(x),yy=Find(y);
32 if (xx!=yy) f[xx]=yy;
33 }
34 memset(mark,0,sizeof(mark));
35 int ans=0;
36 for (int i=0;i<n;i++) {
37 int k=Find(i);
38 mark[k]++;
39 }
40 int cnt=0;
41 for (int i=0;i<n;i++) {
42 if (mark[i]>1) cnt++;
43 }
44 if (cnt==1) {
45 ans=0;
46 for (int i=0;i<n;i++) {
47 if (g[i].size()&1) ans++;
48 }
49 printf("%d\n",ans/2);
50 continue;
51 }
52 for (int i=0;i<n;i++) {
53 if (mark[i]>1) {
54 ans++;
55 int tmp=0;
56 for (int j=0;j<n;j++) {
57 if (Find(j)==i&&(g[j].size()&1)) {
58 tmp++;
59 }
60 }
61 if (tmp>2) ans+=(tmp-2)/2;
62 }
63 }
64 printf("%d\n",ans);
65 }
66 return 0;
67 }
2 #include<cstring>
3 #include<algorithm>
4 #include<vector>
5 using namespace std;
6 const int N=1010;
7 vector<int>g[N];
8 int f[N];
9 int n,m;
10 int mark[N];
11
12 int Find(int x)
13 {
14 return (x==f[x])?x:(f[x]=Find(f[x]));
15 }
16
17 int main()
18 {
19 // freopen("1.in","r",stdin);
20 // freopen("1.out","w",stdout);
21 while (~scanf("%d%d",&n,&m)) {
22 for (int i=0;i<n;i++) {
23 f[i]=i;
24 g[i].clear();
25 }
26 while (m--) {
27 int x,y;
28 scanf("%d%d",&x,&y);
29 g[x].push_back(y);
30 g[y].push_back(x);
31 int xx=Find(x),yy=Find(y);
32 if (xx!=yy) f[xx]=yy;
33 }
34 memset(mark,0,sizeof(mark));
35 int ans=0;
36 for (int i=0;i<n;i++) {
37 int k=Find(i);
38 mark[k]++;
39 }
40 int cnt=0;
41 for (int i=0;i<n;i++) {
42 if (mark[i]>1) cnt++;
43 }
44 if (cnt==1) {
45 ans=0;
46 for (int i=0;i<n;i++) {
47 if (g[i].size()&1) ans++;
48 }
49 printf("%d\n",ans/2);
50 continue;
51 }
52 for (int i=0;i<n;i++) {
53 if (mark[i]>1) {
54 ans++;
55 int tmp=0;
56 for (int j=0;j<n;j++) {
57 if (Find(j)==i&&(g[j].size()&1)) {
58 tmp++;
59 }
60 }
61 if (tmp>2) ans+=(tmp-2)/2;
62 }
63 }
64 printf("%d\n",ans);
65 }
66 return 0;
67 }