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 %s深入解析

    默认我们通常用字符串填充它 'Keep %s, and you will aways make %' % ('moving', 'it') 如果你就此止步,那就错过了一些神乎其技的用法 比如: arr ...

  2. JS 删除对象属性

    updateNode: function(data) { if(data) { this.root[data.id] = data; } }, removeNodes: function(idsArr ...

  3. java2

    1:关键字(掌握) (1)被Java语言赋予特定含义的单词 (2)特点: 全部小写. (3)注意事项: A:goto和const作为保留字存在. B:类似于Notepad++这样的高级记事本会对关键字 ...

  4. SQL操作记录查看工具

    [1]SQL Server Profiler就是一个Sql的监视工具,可以具体到每一行Sql语句,每一次操作,和每一次的连接 [2] 做数据交互时,往往很难直观的看到最后在数据库中执行的SQL语句.此 ...

  5. JavaScript高级程序设计学习笔记--BOM

    window对象 BOM的核心对象是window,它表示浏览器的一个实例.在浏览器中,window对象有双重角色,它既是通过JavaScript访问浏览器窗口的一个接口,又是ECMScript规定的G ...

  6. 【转载】PyQt QSetting保存设置

    转载地址: http://blog.sina.com.cn/s/blog_4b5039210100h3zb.html 用户对应用程序经常有这样的要求:要求它能记住它的settings,比如窗口大小,位 ...

  7. Power BI for Office 365(八)共享查询

    在Power Query中,你不但可以搜索线上的数据,也可以把自己的数据发布到线上供其它人检索.Power Query通过Power BI站点提供了这种内置的分享功能.在Excel中,Anna打开了她 ...

  8. java打包文件夹为zip文件

    //待压缩的文件目录 String sourceFile=sourceFilePath+"\\"+userName; //存放压缩文件的目录 String zipFilePath ...

  9. C# 默认以管理员权限运行程序

    /** * 当前用户是管理员的时候,直接启动应用程序 * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行 */ //获得当前登录的Windows用户标示 //URL:http://w ...

  10. Bulk_Collect_Performance 比较

    上一篇讲到了调用集锦,这篇关注一下性能问题吧. DECLARE CURSOR c_tool_list IS SELECT descr d1 FROM hardware; l_descr hardwar ...