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. 【洛谷1110】[ZJOI2007] 报表统计(两棵平衡树)

    点此看题面 大致题意: 有一个序列,三种操作.\(INSERT\)操作是在原数列第\(i+1\)个元素之前插入一个新元素\(k\),\(MIN\)\(GAP\)操作是查询相邻两个元素的之间差值的最小值 ...

  2. NOIP2018赛前停课集训记(10.24~11.08)

    前言 为了不久之后的\(NOIP2018\),我们的停课从今天(\(Oct\ 24th\))起正式开始了. 本来说要下周开始的,没想到竟提早了几天,真是一个惊喜.毕竟明天有语文考试.后天有科学考试,逃 ...

  3. opencv与灰度图

    https://blog.csdn.net/qq_32211827/article/details/56854985 首先,灰度图可以是一个通道存成图片,也可以是3个通道存成图片,3个通道存成图片,其 ...

  4. web项目小总结

     初步小结 1.之前的CSS有些遗忘,返回去重新看知识点,频繁会浪费项目时间. 比如说: position定位 1 position: absolute;//绝对定位 2 position:relat ...

  5. 操作系统(5)_内存管理_李善平ppt

    i386先通过段是管理,在通过页是管理

  6. fstatfs/statfs详解

    [fstatfs/statfs系统调用]       功能描述:   查询文件系统相关的信息.     用法:   #include <sys/vfs.h>    /* 或者 <sy ...

  7. jqweui 中的tabbar导航

    最近做微信的服务号项目,用的jqweui作为主要的ui,但是对于用惯了ele ui的开发者来说,文档貌似有点不友好.真是很让人头疼! 所以结合着自己做的项目,随便写一点东西. 比如说,tabbar导航 ...

  8. MintLinux

    最近将我的mintlinux进行了一系列外观优化,总算好看了一点

  9. JDK和CGLIB动态代理原理区别

    JDK和CGLIB动态代理原理区别 https://blog.csdn.net/yhl_jxy/article/details/80635012 2018年06月09日 18:34:17 阅读数:65 ...

  10. 最新手机号正则表达式php包括166等号段

    if(!preg_match("/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147)) ...