Ant Trip

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

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
Recommend
gaojie   |   We have carefully selected several similar
problems for you:  3013 3015 3016 3011 3010 
题意:给出N个节点,M个边,问要遍历一遍所有的边,需要的最小group数目。
思路:首先通过并查集判断有几个联通块。然后对于每个联通块,统计需要多少笔。
如果,联通块中,度为奇数节点的个数为0或2个,那就可以一笔画完。
反之,因为一笔最多消去两个度为奇数的节点,所以要最少用奇度数节点个数/2笔。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,tot,ans;
int vis[];
int fa[],num[];
int into[],du[];
int find(int x){
if(fa[x]==x) return fa[x];
else return fa[x]=find(fa[x]);
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
tot=;ans=;
memset(du,,sizeof(du));
memset(vis,,sizeof(vis));
memset(num,,sizeof(num));
memset(into,,sizeof(vis));
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
into[x]++;into[y]++;
int dx=find(x);int dy=find(y);
if(dx!=dy) fa[dy]=dx;
}
for(int i=;i<=n;i++){
int now=find(i);
if(!vis[now]){
vis[now]=;
num[++tot]=now;
}
if(into[i]%!=) du[now]++;
}
for(int i=;i<=tot;i++){
if(into[num[i]]==) continue;
if(du[num[i]]==) ans++;
ans+=du[num[i]]/;
}
cout<<ans<<endl;
}
}

HDU 3108 Ant Trip的更多相关文章

  1. [欧拉回路] hdu 3018 Ant Trip

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) ...

  2. hdu 3018 Ant Trip 欧拉回路+并查集

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  3. HDU 3018 Ant Trip (欧拉回路)

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. HDU 3018 Ant Trip(欧拉回路,要几笔)

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. HDU 3018 Ant Trip (并查集求连通块数+欧拉回路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 题目大意:有n个点,m条边,人们希望走完所有的路,且每条道路只能走一遍.至少要将人们分成几组. ...

  6. HDU 3018 Ant Trip

    九野的博客,转载请注明出处:  http://blog.csdn.net/acmmmm/article/details/10858065 题意:n个点m条边的无向图,求用几笔可以把所有边画完(画过的边 ...

  7. 一本通1530 Ant Trip

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

  8. HDU3018:Ant Trip(欧拉回路)

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. hdu-3018 Ant Trip(欧拉路径)

    题目链接: Ant Trip Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. echarts图表属性说明

    参考博客: https://blog.csdn.net/luanpeng825485697/article/details/76691965

  2. Python-基础-day4

    深浅copy 1.先看赋值运算 h1 = [1,2,3,['aihuidi','hhhh']] h2 = h1 h1[0] = 111 print(h1) print(h2) #结果: # [111, ...

  3. hive用mysql作元数据代替默认derby的hive-site.xml配置

    <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://s ...

  4. keil5下载程序时出现“internal command error”解决方法

    今天下载的时候,插入下载器,查看Debug可用看到“internal command error”,一直找不到原因,后来查看上一个工程才发现,上一个程序禁用了Seral Wire 引脚,导致的. 解决 ...

  5. like

    5.在WHERE中使用like做模糊查询    %符号表示0到多个任意字符    _符号表示1个任意字符     //查询名字中含有O字符的员工信息   select empno,ename   fr ...

  6. ZOJ 2705

    这题,找找规律,可以发现一个斐波那契数列.按照斐波那契数列求和,知道, SUM=Fn+2-F1,于是,该长度为Fn+2的倍数.因为斐波那契数列不一定是从1开始的,而从2开始的每个数都是从1开始的倍数. ...

  7. 《Objective-C高级编程:iOS与OS X多线程和内存管理》读后感

    拿到这本书的第一感觉是非常薄,可是内容就如同序里面所说,这不是一本面向刚開始学习的人的书,比較有深度,对C/C++全然不熟悉的话非常多东西会看不明确. 尽管此书在技术点上仅仅谈到了ARC.Blocks ...

  8. Hadoop实战:使用Combiner提高Map/Reduce程序效率

    好不easy算法搞定了.小数据測试也得到了非常好的结果,但是扔到进群上.挂上大数据就挂了.无休止的reduce不会结束了. .. .. .... .. ... .. ================= ...

  9. linux怎么开启telnet服务

    1>编辑telent的配置文件/etc/xinetd.d/telnet 如下: (设置disable = no,也就是开启telnet服务) service telnet { disable = ...

  10. javascript系列-class10.DOM(下)

    1.node节点(更详细的获取(设置)页面中所有的内容)         根据 W3C 的 HTML DOM 标准,HTML 文档中的所有内容都是节点:   元素是节点的别称,节点包含元素当然节点还有 ...