Vasya went for a walk in the park. The park has n glades, numbered from 1 to n. There are m trails between the glades. The trails are numbered from 1 to m, where the i-th trail connects glades xi and yi. The numbers of the connected glades may be the same (xi = yi), which means that a trail connects a glade to itself. Also, two glades may have several non-intersecting trails between them.

Vasya is on glade 1, he wants to walk on all trails of the park exactly once, so that he can eventually return to glade 1. Unfortunately, Vasya does not know whether this walk is possible or not. Help Vasya, determine whether the walk is possible or not. If such walk is impossible, find the minimum number of trails the authorities need to add to the park in order to make the described walk possible.

Vasya can shift from one trail to another one only on glades. He can move on the trails in both directions. If Vasya started going on the trail that connects glades a and b, from glade a, then he must finish this trail on glade b.

Input

The first line contains two integers n and m (1 ≤ n ≤ 106; 0 ≤ m ≤ 106) — the number of glades in the park and the number of trails in the park, respectively. Next m lines specify the trails. The i-th line specifies the i-th trail as two space-separated numbers, xi, yi (1 ≤ xi, yi ≤ n) — the numbers of the glades connected by this trail.

Output

Print the single integer — the answer to the problem. If Vasya’s walk is possible without adding extra trails, print0, otherwise print the minimum number of trails the authorities need to add to the park in order to make Vasya’s walk possible.

Examples

input

3 3
1 2
2 3
3 1

output

0

input

2 5
1 1
1 2
1 2
2 2
1 2

output

1

Note

In the first test case the described walk is possible without building extra trails. For example, let’s first go on the first trail, then on the second one, and finally on the third one.

In the second test case the described walk is impossible without adding extra trails. To make the walk possible, it is enough to add one trail, for example, between glades number one and two.

Solution

先跑dfs求出每个联通块的奇度点个数 然后从1开始 如果一个块不是一个点 就和当前的合并 最后合并成大联通块,大联通块的答案为奇数度点个数/2.

Code

#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
const int maxn = 1000005;
inline int getint() {
int r = 0; bool z = true; char c = getchar();
for (; '0' > c || c > '9'; c = getchar()) if (c == '-') z = false;
for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c;
return z ? r : (-r);
}
struct edge_type {int to, next; } edge[maxn<<1];
int cnte, h[maxn], cnt[maxn], du[maxn], x, y, tot, n, m, ans;
bool vis[maxn], ava[maxn];
void ins(int x, int y) {
edge[++cnte].to = y;
edge[cnte].next = h[x];
h[x] = cnte;
}
void dfs(int now) {
vis[now] = true;
if (du[now] & 1) ++cnt[tot];
for (int i = h[now]; i; i = edge[i].next)
if (!vis[edge[i].to])
dfs(edge[i].to);
}
int combine(int a, int b) {
++ans;
if (a == 0 && b == 0) return 2;
if (a == 0 || b == 0) return a + b;
return a + b - 2;
}
int main() {
n = getint(); m = getint();
for (int i = 0; i < m; ++i) {
x = getint();
y = getint();
ins(x, y);
ins(y, x);
++du[x];
++du[y];
}
for (int i = 1; i <= n; ++i)
if (!vis[i]) {
++tot;
if (du[i] == 0) {vis[i]=true;ava[tot]=false;}
else {dfs(i);ava[tot]=true;}
}
int nowdu = cnt[1];
for (int i = 2; i <= tot; ++i)
if (ava[i])
nowdu = combine(nowdu, cnt[i]);
ans += nowdu / 2;
printf("%d\n", ans);
return 0;
}

 

Codeforces 209 C. Trails and Glades的更多相关文章

  1. CodeForces 209C Trails and Glades

    C. Trails and Glades time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. Codeforces.209C.Trails and Glades(构造 欧拉回路)

    题目链接 \(Description\) 给定一张\(n\)个点\(m\)条边的无向图,允许有自环重边.求最少加多少条边后,其存在从\(1\)出发最后回到\(1\)的欧拉回路. 注意,欧拉回路是指要经 ...

  3. CF209C Trails and Glades

    题目链接 题意 有一个\(n\)个点\(m\)条边的无向图(可能有重边和自环)(不一定联通).问最少添加多少条边,使得可以从\(1\)号点出发,沿着每条边走一遍之后回到\(1\)号点. 思路 其实就是 ...

  4. CF209C Trails and Glades(欧拉路)

    题意 最少添加多少条边,使无向图有欧拉回路. n,m≤106 题解 求出每个点的度数 奇度数点需要连一条新边 仅有偶度数点的连通块需要连两条新边 答案为上面统计的新边数 / 2 注意:此题默认以1为起 ...

  5. Codeforces Round #209 (Div. 2) B. Permutation

    解题思路: 如果序列a是单调递增的,则序列为1,2,..... 2n,则将给出的式子化简得Σ(a2i - a2i-1) = n 如果序列a是单调递减的,则序列为2n,.........2, 1,则将给 ...

  6. Codeforces Round #209 (Div. 2) A. Table

    #include <iostream> #include <vector> using namespace std; int main(){ int n,m; cin > ...

  7. Codeforces Round #209 (Div. 2)C

    刷了一页的WA  ..终于发现了 哪里错了 快速幂模板里一个变量t居然开得long  ... 虽然代码写的丑了点 但是是对的 那个该死的long 啊.. #include <iostream&g ...

  8. Codeforces Round #209 (Div. 2)

    A: 要么是两次要么4次,判断是否在边界: #include<cstdio> using namespace std; int main() { int n,m,x; ; scanf(&q ...

  9. Codeforces Round #209 (Div. 2)A贪心 B思路 C思路+快速幂

    A. Table time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. Python全栈开发【基础一】

    Python全栈开发[第一篇] 本节内容: Python 的种类 Python 的环境 Python 入门(解释器.编码.变量.input输入.if流程控制与缩进.while循环) if流程控制与wh ...

  2. Class.forName的使用

    Class.forName的使用 Class.forName返回一个类,使用此方法可以获取类 首先,创建一个Student类 /*** * This Class is for Student bean ...

  3. linux学习笔记-(1)-安装

    学习的第一部,当然是寻找学习资料,如今的网络如此发达,只要下点功夫,基本上能在网上找到一切自己所需要的东西,而且还是免费滴哟! ---------------------分割线------------ ...

  4. springMVC含文件上传调用ajax无法连接后台

    springMVC在使用ajax进行后台传值的时候发现找不到对应的requestMapping(""),无法进入后台,在多次试验后确定是 MultipartFile对象与ajax冲 ...

  5. life_motto

    simple,dedicated,healthy life style,love those u love...

  6. iOS--创建炫酷的渐变色界面

    { CAGradientLayer *_layer; } //创建渐变层 _layer =[CAGradientLayer layer]; _layer.frame=self.view.frame; ...

  7. 最详细易懂的CRC-16校验原理(附源程序)

    from:http://www.openhw.org/chudonganjin/blog/12-08/230184_515e6.html 最详细易懂的CRC-16校验原理(附源程序) 1.循环校验码( ...

  8. java基础-包

    浏览以下内容前,请点击并阅读 声明 为了使类型更容易查找和使用,避免命名冲突,以及可视范围的控制,程序员一般将相关的一些类型组合到一个包中.组合的类型包括类,接口,枚举和注释,枚举是一种特殊的类,而注 ...

  9. S​Q​L​获​取​当​前​时​间​(​日​期​)

    --获取当前日期(如:yyyymmdd) select CONVERT (nvarchar(12),GETDATE(),112) --获取当前日期(如:yyyymmdd hh:MM:ss) selec ...

  10. 【BZOJ1251】序列终结者 Splay

    一道模板题,一直没发现自己的快速读入读不了负数,我竟然能活到现在真是万幸. #include <iostream> #include <cstdio> #define inf ...