Ant Trip

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2010    Accepted Submission(s): 782

Problem Description
Ant Country consist of N towns.There are M roads connecting the towns.

Ant Tony,together with his friends,wants to go through every part of the country.

They intend to visit every road , and every road must be visited for
exact one time.However,it may be a mission impossible for only one
group of people.So they are trying to divide all the people into several
groups,and each may start at different town.Now tony wants to know what
is the least groups of ants that needs to form to achieve their goal.

 
Input
Input
contains multiple cases.Test cases are separated by several blank
lines. Each test case starts with two integer
N(1<=N<=100000),M(0<=M<=200000),indicating that there are N
towns and M roads in Ant Country.Followed by M lines,each line contains
two integers a,b,(1<=a,b<=N) indicating that there is a road
connecting town a and town b.No two roads will be the same,and there is
no road connecting the same town.
 
Output
For each test case ,output the least groups that needs to form to achieve their goal.
 
Sample Input
3 3
1 2
2 3
1 3

4 2
1 2
3 4

 
Sample Output
1
2

Hint

New ~~~ Notice: if there are no road connecting one town ,tony may forget about the town.
In sample 1,tony and his friends just form one group,they can start at either town 1,2,or 3.
In sample 2,tony and his friends must form two group.

 
Source
 
 
一个连通图不会有奇数个奇数度顶点,画一画图可以知道,假如一个连通图所有点度数为偶数,答案为1,否则就是奇数度顶点的一半,累加求和。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int father[maxn];
int indegree[maxn];
int n,m;
int a[maxn];
void init(){
for(int i=;i<=n;i++)
father[i]=i;
}
int find(int u){
if(father[u]!=u)
father[u]=find(father[u]);
return father[u];
}
void Union(int x,int y){
int t1=find(x);
int t2=find(y);
if(t1!=t2)
father[t1]=t2;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
init();
// memset(father,0,sizeof(father));
memset(indegree,,sizeof(indegree));
memset(a,-,sizeof(a));
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
indegree[u]++;
indegree[v]++;
Union(u,v);
} for(int i=;i<=n;i++){
int t=find(i);
if(a[t]==-&&indegree[i]>)
a[t]=;
if(indegree[i]&)
a[t]++;
}
int ans=;
for(int i=;i<=n;i++){
if(a[i]==)
ans++;
else if(a[i]>)
ans+=a[i]/;
}
printf("%d\n",ans);
}
return ;
}

HDU3018 几笔画(非1笔)的更多相关文章

  1. hdu3018 一笔画问题

    题意:       给你一幅画,这幅画由点和边构成,问你最少几笔能把这幅画画完. 思路:      这个题目的结论比较巧妙,首先我们考虑下,如果给的图是欧拉图,或者是条欧拉回路,那么我们一笔就搞定了, ...

  2. nyoj-----42一笔画问题

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  3. 23个适合logo设计的常用英文字体

    在很多国外的品牌中我们都会发现他们的英文字体在logo的运用中,不仅会提升logo的品质还会让logo看起来更加美观.今天我们就来看看都有哪些常常出现在logo设计中的英文字体吧.   字体,与文字本 ...

  4. [No0000A9]实用word用法

    目录  TOC \o "1-3" \h \z \u 三招去掉页眉那条横线.... PAGEREF _Toc465252982 \h 08D0C9EA79F9BACE118C8200 ...

  5. Blue Path(基于cocos2dx 3.0)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=498 iTunes下载:http ...

  6. zw字王《中华大字库》2018版升级项目正式启动

    zw字王<中华大字库>2018版升级项目正式启动 https://www.cnblogs.com/ziwang/p/9500537.html 这次升级是和字库协会一起合作,首批推出的字体, ...

  7. 一本通1530 Ant Trip

    1530:Ant Trip [题目描述] 原题来自:2009 Multi-University Training Contest 12 - Host by FZU 给你无向图的 N 个点和 M 条边, ...

  8. Ant Trip HDU - 3018(欧拉路的个数 + 并查集)

    题意: Ant Tony和他的朋友们想游览蚂蚁国各地. 给你蚂蚁国的N个点和M条边,现在问你至少要几笔才能所有边都画一遍.(一笔画的时候笔不离开纸) 保证这M条边都不同且不会存在同一点的自环边. 也就 ...

  9. 预备作业02 : 体会做中学(Learning By Doing)

    1.你有什么技能比大多人(超过班级90%以上)更好? 如果说不算上玩玻璃球在诸如此类不登大雅之堂的技能,我想我是没有什么比大多数人更好的.我的兴趣还算广泛,但很多东西也只是学到了皮毛而已. 在我上初中 ...

随机推荐

  1. IOS 自定义Layer(图层)

    方式1: @interface NJViewController () @end @implementation NJViewController - (void)viewDidLoad { [sup ...

  2. 【转】iOS学习笔记(八)——iOS网络通信http之NSURLConnection

    移动互联网时代,网络通信已是手机终端必不可少的功能.我们的应用中也必不可少的使用了网络通信,增强客户端与服务器交互.这一篇提供了使用NSURLConnection实现http通信的方式. NSURLC ...

  3. python_43_移动文件指针补充

    #移动文件指针补充 ''' 文件对象.seek((offset,where)) offset:移动的偏移量,单位为字节.等于正数时向文件尾方向移动,等于负数时向文件头方向移动文件指针 where:指针 ...

  4. datetime 插件

    1  写一段文本 <div id="nomarl-wrap"> <div class="form-group"> <label c ...

  5. CUDA:Supercomputing for the Masses (用于大量数据的超级计算)-第二节

    原文链接 第二节:第一个内核 Rob Farber 是西北太平洋国家实验室(Pacific Northwest National Laboratory)的高级科研人员.他在多个国家级的实验室进行大型并 ...

  6. ES6学习(一):数值的扩展

    chapter06 数值的扩展 6.1 二进制和八进制 二进制 前缀 0b 或者 0B 八进制 前缀 0o 或者 0O 6.2 Number.isFinite() Number.isNaN() 原先这 ...

  7. c++引用与指针的区别

    c++引用与指针的区别 ★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名. 指针的权威定义: In a declaration T D where ...

  8. 学习 KMP 算法

    KMP 算法是用来处理字符串匹配问题的.也就是给你两个字符串,你需要回答:B 串是否是 A 串的子串(或 B 串在 A 串中出现的位置).比如,字符串 A = “ i am student ”, 字符 ...

  9. 爬虫学习(九)——登录获取cookie爬取

    import urllib.requestimport urllib.parseimport http.cookiejar # http.cookiejar 该包是专门对网页的cookie只进行获取的 ...

  10. 判断浏览器环境(QQ,微信,安卓设备,IOS设备,PC微信环境,移动设备)

    判断浏览器环境(QQ,微信,安卓设备,IOS设备,PC微信环境,移动设备) // ===== 判断浏览器环境 ===== // // 判断是否是QQ环境 function isQQ() { retur ...