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. html复选框

    1.添加复选框 <input type="checkbox" id="yc" name="yc" value="year&q ...

  2. 神奇的background

    background:url() fixed ....  可以实现页面向下滚动时背景图片 保持位置不变   感觉好像背景在随鼠标滚动而滚动一样

  3. Keil提示premature end of file错误 无法生成HEX文件

    今天舍友在使用Keil UV4的时候遇到一个问题:Keil提示premature end of file,无法生成hex文件. 代码是没有错误的.那么问题就出在设置上面了. 百度了一圈,发现很少人解答 ...

  4. cocos2dx lua中异步加载网络图片,可用于显示微信头像

    最近在做一个棋牌项目,脚本语言用的lua,登录需要使用微信登录,用户头像用微信账户的头像,微信接口返回的头像是一个url,那么遇到的一个问题就是如何在lua中异步加载这个头像,先在引擎源码里找了下可能 ...

  5. oracle 数据的导入导出

    一.数据导出 1.为输出路径建立一个数据库的directory对象. create or replace directory dumpdir as 'd:\'; 可以通过:select * from ...

  6. Unity黑巧克力 滚球游戏 入门级教程

    <黑巧克力>系列教程是适合于新手上手Unity的教程,本教程适合作为初次接触Unity(零基础)的第一篇的教程.学习本教程需要有的基础是:线性代数.编程基础.Csharp语言基础.Unit ...

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

    201521123082 <Java程序设计>第7周学习总结 标签(空格分隔): Java 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1. ...

  8. 201521123074 《Java程序设计》第5周学习总结

    1.本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 接口定义了解:接口(interface)就是方法声明和常量值的集合. 几种接口讲解 ...

  9. 201521123081《Java程序设计》 第1周学习总结

    #1. 本周学习总结 ###JAVA是1995年SUN推出的一种简单的,跨平台的,面向对象的,分布式的,解释的,健壮的,安全的,结构的,中立的,可移植的,性能很优异的,多线程的,动态的语言.是世界上广 ...

  10. 201521123103 《java学习笔记》 第十二周学习总结

    一.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 二.书面作业 将Student对象(属性:int id, String name,int age,double ...