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. 我与A协

    大学毕业以后发现离曾经的圈子越来越远,非常怀念原来在A协和大家一起奋斗的日子,在这里写一篇文章,献给有很多美好回忆的A协,也献给渐渐远离A协的我. 首先,回顾一下我为什么会参与到A协的建设工作中来.我 ...

  2. c/c++字符串定义及使用的对比

    c/c++中使用字符串的频率还是比较高的,下面就字符串的不同定义及其使用方法做一些对比 字符串一般有以下三种定义方法: 1.char *p="hello"; 2.char str[ ...

  3. 多个SVG图形集成到一个SVG图形上

    SVG:使用XML格式定义图像的可缩放矢量图形(Scalable Vector Graphics). 优点就不多说了,下面看看怎么将多个svg图形集成到一个svg图形上. 如果使用bootstrap框 ...

  4. 【Java EE 学习 36】【struts2】【struts2系统验证】【struts2 ognl值栈】【struts2 ongl标签】【struts2 UI标签】【struts2模型驱动和令牌机制】

    一.struts2系统验证 1.基于struts2系统验证的方式实际上就是通过配置xml文件的方式达到验证的目的. 2.实际上系统校验的方法和手工校验的方法在底层的基本实现是相同的.但是使用系统校验的 ...

  5. Cycles渲染研究测试效果图

    从左到右:.贴图镂空透明  2.纹理半透明  3.纹理  4.材质半透明  5.材质 输入输出节点信息如下: ############################################# ...

  6. [JAVA]HTTP请求应答作输入输出

    请求(需要发送数据给别人): URL url = new URL("需要请求的URL连接"); HttpURLConnection httpConnection = (HttpUR ...

  7. 三言两语之js面向对象初探1

    http://www.cnblogs.com/54td/p/5580994.htm    先是有了这个比较简短但是内容比较丰盈的上篇,现在时间比较充沛,所以详细写来.搞前端的同学经常被其他程序员bs, ...

  8. oracle的回收站介绍

    昨天做的展示oracle表空间功能剩余空间的功能,发现查询表dba_free_space时特别慢,经网上搜索,说是由于表空间碎片和回收站(Oracle 10g以后才有)引起的,后来搜到一片介绍回收站的 ...

  9. 前台json 的一些 处理 (转)

    JS解析json数据并将json字符串转化为数组的实现方法 转自(http://www.jb51.net/article/32795.htm) <!DOCTYPE HTML PUBLIC &qu ...

  10. java多线程面试题

    很多核心Java面试题来源于多线程(Multi-Threading)和集合框架(Collections Framework),理解核心线程概念时,娴熟的实际经验是必需的.这篇文章收集了Java线程方面 ...