Ant Trip

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

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

欧拉回路简单题:

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
using namespace std;
#define ll long long int
int a[];
int aa[];
int find(int x)
{
while(x!=a[x])x=a[x];
return x;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(aa,,sizeof(aa));
int i,x,y;
int b[n+];
for(i=; i<=n; i++)
a[i]=i;
memset(b,,sizeof(b));
for(i=; i<m; i++)
{
scanf("%d%d",&x,&y);
b[x]++;
b[y]++;
int fx=find(x);
int fy=find(y);
if(fy!=fx)
a[fy]=fx;
}
int sum=;
for(i=; i<=n; i++)
{
if(b[i]&)
aa[find(a[i])]++;
}
for(i=; i<=n; i++)
{
int tt=find(a[i]);
if(b[i]&&tt==i)
{
if(aa[tt])
sum+=aa[tt]/;
else sum++;
}
}
cout<<sum<<endl;
} }

hdu3018欧拉回路题的更多相关文章

  1. 【UOJ#177】欧拉回路

    [UOJ#177]欧拉回路 题面 UOJ 题解 首先图不连通就没啥好搞的了. 对于无向图而言,每个点度数为偶数. 对于有向图而言,每个点入度等于出度. 然后就是一本通上有的做法,直接\(dfs\)一遍 ...

  2. 洛谷P2731 骑马修栅栏 Riding the Fences

    P2731 骑马修栅栏 Riding the Fences• o 119通过o 468提交• 题目提供者该用户不存在• 标签USACO• 难度普及+/提高 提交 讨论 题解 最新讨论 • 数据有问题题 ...

  3. UVa10129(还没ac)各种re,o(╥﹏╥)o

    这是一道欧拉回路题 欧拉回路:就是一个路径包括每条边恰好一次. 判断是否满足欧拉回路.首先是图是联通的.其次图中每个点的入度等于出度.如果是欧拉路径的话,满足奇点只能等于2或0,并且对于有向图,奇点的 ...

  4. hdu--1878--欧拉回路(并查集判断连通,欧拉回路模板题)

     题目链接 /* 模板题-------判断欧拉回路 欧拉路径,无向图 1判断是否为连通图, 2判断奇点的个数为0 */ #include <iostream> #include <c ...

  5. 欧拉回路(hdu3018)

    刚学图论不久,看着别人的博客慢慢学了一点基础的,感觉还是有点力不从心,感觉图论的题好多长得都很像,什么太监算法(Tarjan),Kosaraju,当然最基础的还是并查集...好了继续介绍这道题.... ...

  6. Uva 10596 - Morning Walk 欧拉回路基础水题 并查集实现

    题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起 ...

  7. 【转】欧拉回路&特殊图下的哈密顿回路题集

    转自:http://blog.csdn.net/shahdza/article/details/7779385 欧拉回路[HDU]1878 欧拉回路 判断3018 Ant Trip 一笔画问题1116 ...

  8. hdu1116--解题报告--初步了解欧拉回路

    由题目意思..我们只要把n个字符串的首尾字母看作是点,这个字符串看着边来处理就可以啦...将题目的案例图形化如下: 那么接着就是欧拉路径和欧拉回路判断,我们这里用并査集来判断图是不是连通的,然后根据有 ...

  9. PAT甲题题解-1126. Eulerian Path (25)-欧拉回路+并查集判断图的连通性

    题目已经告诉如何判断欧拉回路了,剩下的有一点要注意,可能图本身并不连通. 所以这里用并查集来判断图的联通性. #include <iostream> #include <cstdio ...

随机推荐

  1. mysql中group by 的用法解析

    1. group by的常规用法 group by的常规用法是配合聚合函数,利用分组信息进行统计,常见的是配合max等聚合函数筛选数据后分析,以及配合having进行筛选后过滤. 假设现有数据库表如下 ...

  2. C#构建DataTable(转)

    Asp.net DataTable添加列和行的方法 方法一: DataTable tblDatas = new DataTable("Datas"); DataColumn dc ...

  3. linux使用bbswitch+nvidia-xrun取代bumblebee

    nvidia-xrun的比bumblebee使用nvidia optimus的性能更好,关键是xrun支持Vulkan. 本文保存并更新在github:levinit/itnotes/linux/ar ...

  4. AJAX 处理xml 数据

    //这个方式返回的得是 xml标准的对象,可以返回 xml字符串,前端js 使用转为xml   function createXml(str){ if(document.all){//IE浏览器 va ...

  5. 转:面向切面编程AOP的理解

    AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.OOP引入 ...

  6. 转: 【Java并发编程】之十三:生产者—消费者模型(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17249321 生产者消费者问题是线程模型中的经典问题:生产者和消费者在同一时间段内共用同一 ...

  7. 201521123113 《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. -继承设计的技巧 1.将公共操作和属性放在父类 2.不要使用protected修 ...

  8. 201521123061 《Java程序设计》第四周学习总结

    201521123061 <Java程序设计>第四周学习总结 1. 本章学习总结 (1)思维导图: --- (2)上课内容总结: 第四周学习了Java中的继承与多态,思维导图中已经给出了本 ...

  9. 201521123103 《Java学习笔记》第二周学习笔记

    一.本周学习总结 1.学习了数据类型的使用:整数类型.浮点类型. boolean类型.数组等以及类型的转换,最重要的是学会了import引用包: 2.学习了string类对象的拼接.字符串池.枚举类型 ...

  10. 201521123071 《JAVA程序设计》第二周学习总结

    1. 本周学习总结 在本周的学习中,主要学习了书上的String类以及Math类等知识,但是书上学到的东西只是理论,实际打起代码来的时候会学习到更多,比如在PTA上就有学习到StringBuilder ...