比赛 20151026 评测结果 AAAAAAAAAA
题目名称 游历校园 最终得分 100
用户昵称 zhengtn03 运行时间 0.986 s
代码语言 C++ 内存使用 1.84 MiB
提交时间 2015-10-26 20:47:26
显示代码纯文本
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<sstream>
#include<iomanip>
#include<stdlib.h>
using namespace std;

vector<int> G[100010];
int used[100010];
int oddNumber;

int DFS(int point)
{
	int temp = G[point].size();
	if (temp % 2 == 1)
	{
		oddNumber++;
	}
	int ans = 1;
	used[point] = 1;
	for (int i = 0; i < G[point].size(); i++)
	{
		if (used[G[point][i]] == 0)
		{
			ans += DFS(G[point][i]);
		}
	}
	return ans;
}

int main()
{
	freopen("sent.in", "r", stdin);
	freopen("sent.out", "w", stdout);
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int point1, point2;
		scanf("%d%d", &point1, &point2);
		point1--;
		point2--;
		G[point1].push_back(point2);
		G[point2].push_back(point1);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (used[i] == 0)
		{
			oddNumber = 0;
			int pointNumber = DFS(i);
			if (pointNumber != 1)
			{
				ans++;
				if (oddNumber >= 2)
				{
					ans += (oddNumber - 2) / 2;
				}
			}
		}
	}
	ans--;
	printf("%d\n", ans);
	return 0;
}