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. 下拉列表 select-option ; select-optgroup-option

    HTML中的下拉列表: <select> <option value ="1">Volvo</option> <option value  ...

  2. 一款全兼容的播放器 videojs

    [官网]http://www.videojs.com/ videojs就提供了这样一套解决方案,他是一个兼容HTML5的视频播放工具,早期版本兼容所有浏览器,方法是:提供三个后缀名的视频,并在不支持h ...

  3. CentOS7 词典

    goldendict sudo yum install goldendict打开goldendict,阅读welcome,添加本地词典,在http://abloz.com/huzheng/stardi ...

  4. int main( int argc, char **argv)

    1.参数 (有时参数是void) argc是程序运行时参数个数 argv是存储参数的数组,可以用char* argv[],也可以用char **argv. 例如编译一个hello.c的程序 1 #in ...

  5. 如何在WIN2008或WIN2012 64位系统安装32位SQL2000

    如何在WIN2008或WIN2012 64位系统安装32位SQL2000 在日常服务器,云服务器或VPS中,因尔特网络工程师遇到部分使用了WIN2008 或WN2012 64位系统的用户需要安装SQL ...

  6. mvc+webapi 项目架构

    首先项目是mvc5+webapi2.0+orm-dapper+ef codefirst+redis+quartz.net+actionmq. 1.项目框架层次结构: 这个mvc项目根据不同的业务和功能 ...

  7. Linux常用命令学习4---(挂载命令mount umount、用户登陆查看和用户交互命令 w who last lastlog)

    紧接着上一篇Linux的命令行的学习:Linux学习3---(文件的压缩和解压缩命令zip unzip tar.关机和重启命令shutdown reboot……) 1.挂载命令     简介      ...

  8. 【Java EE 学习 35 上】【strus2】【类型转换器】【struts2和Servlet API解耦】【国际化问题】【资源文件乱码问题已经解决】

    一.类型转换器 1.在动作类action中,声明和表单中name属性的值同名的属性,提供get和set方法,struts2就可以通过反射机制,从页面中获取对应的内容 package com.kdyzm ...

  9. 关于vector的内存释放问题

    以前一直想当然的以为vector 的clear()函数会保证释放vector的内存,今天网上一查资料发现完全不是我想象的那样子. 比如有如下代码: tempObject obj1; tempObjec ...

  10. linq学习笔记

    最近在学习linq的一些基础知识,看了c#高级编程及阅读了园子内部几篇优秀的博文,有所体会,感觉应该记录下来,作为以后复习使用.都是一些最基础的知识,大致分为三个部分:linq预备知识:linq查询: ...