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

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, xiyi(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, print 0, 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.

并查集判联通块。

如果只有一个联通块,答案为奇度数节点数/2,

如果有多个联通块,答案为奇度数节点数/2 + 没有奇度数点的联通块个数

由于1点必须在欧拉回路中,1点默认要设为存在。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const int mx[]={,,,-,};
const int my[]={,,,,-};
const int INF=1e9;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
int fa[mxn];
int find(int x){
if(fa[x]==x)return x;
return fa[x]=find(fa[x]);
}
void init(int x){
for(int i=;i<=x;i++)fa[i]=i;
}
int deg[mxn];
int cnt[mxn],ans=;
bool flag[mxn];
bool vis[mxn];
int cct=;
int main(){
n=read();m=read();
int i,j,u,v;
init(n);
vis[]=;
for(i=;i<=m;i++){
u=read();v=read();
if(u!=v){
deg[u]++;
deg[v]++;
vis[u]=;vis[v]=;
u=find(u);v=find(v);
fa[u]=v;
}
else vis[u]=;
}
for(i=;i<=n;i++){
if(!vis[i])continue;
if(find(i) ==i)cct++;
}
for(i=;i<=n;i++){
if(!vis[i] || deg[i]%==)continue;
int x=find(i);
cnt[x]++;
}
int res=;
for(i=;i<=n;i++){
if(!vis[i])continue;
if(find(i)==i){
if(!cnt[i])ans++;
else res+=cnt[i];
}
}
if(cct==)printf("%d\n",res/);
else printf("%d\n",ans+res/);
return ;
}

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

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

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

  2. Codeforces 209 C. Trails and Glades

    Vasya went for a walk in the park. The park has n glades, numbered from 1 to n. There are m trails b ...

  3. CF209C Trails and Glades

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

  4. CF209C Trails and Glades(欧拉路)

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

  5. codeforces 459E

    codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. Nodejs生态圈的TypeScript+React

    基于Nodejs生态圈的TypeScript+React开发入门教程   基于Nodejs生态圈的TypeScript+React开发入门教程 概述 本教程旨在为基于Nodejs npm生态圈的前端程 ...

  2. java:集合的自定义多重排序

    问题: 有一个乱序的对象集合,要求先按对象的属性A排序(排序规则由业务确定,非A-Z或0-9的常规顺序),相同A属性的记录,按根据属性B排序(排序规则,同样由业务确定,非常规顺序) -前提:业务规则是 ...

  3. jboss eap 6.3 域(Domain)模式配置

    jboss提供了二种运行模式:standalone(独立运行模式).domain(域模式),日常开发中,使用standalone模式足已:但生产部署时,一个app,往往是部署在jboss集群环境中的, ...

  4. hadoop家族之pig入门

    昨天成功运行第一个在hadoop集群上面的python版本的wordcount,今天白天继续看网上提供的文档.下午上头给定的回复是把hadoop家族都熟悉一下,那就恭敬不如从命,开始学习pig吧- 这 ...

  5. 学习SQLite之路(四)

    20160621 更新 参考: http://www.runoob.com/sqlite/sqlite-tutorial.html 1. SQLite   alter命令:不通过执行一个完整的转储和数 ...

  6. Android多线程文件下载

    版本信息 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion " ...

  7. java lambda表达式学习笔记

    lambda是函数式编程(FP,functional program),在java8中引入,而C#很早之前就有了.在java中lambda表达式是'->',在C#中是‘=>’. 杜甫说:射 ...

  8. 【Javascript】好用的js弹层插件,layerUI

    官网:layerUI 中文手册:layerAPI

  9. ubuntu中安装VMWare tools

    在进入VMware Workstation之后找到虚拟机然后选择安装VMWare Tools 在下载的安装包中找到linux.iso,比如我的是C:\Program Files (x86)\VMwar ...

  10. android 一条线

    还在为布局的时候做不出来一条细细的线而烦恼么? 哈哈,自从知道了写法腰也不酸了,腿也不疼了!一口气写100行!! <View android:layout_height="1px&qu ...