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. MongoDB副本集模式安装

    设备: 三个1G.20G.1核的虚拟机,系统是SentOS7 min 设置目录: Server1: mkdir -p /home/mongoshard/data/shard11 /home/mongo ...

  2. 一、Solr的相关概念了解

    1.1. 什么是Solr Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务器.Solr提供了比Lucene更为丰富的查询语言,同时实现了可配置.可扩展 ...

  3. import和require

    es6 的 import 语法跟 require 不同,而且 import 必须放在文件的最开始,且前面不允许有其他逻辑代码,这和其他所有编程语言风格一致. import不同与require,它是编译 ...

  4. 根据本周本月本日来查询数据 C#winform数据查询

    这个我是在winform的页面上做的 1. 首先是在页面上添加3个lable   第一次点击lable会有相应的数据被查询出来  第二次点击同一个lable会刷新所有的数据 2.点击不同的label会 ...

  5. Java基础学习 —— 对象的克隆

    对象的克隆分为对象的浅克隆和深克隆 一.对象的浅克隆 注意事项: 1.如果一个对象需要调用clone的方法克隆,那么该对象必须要实现Cloneable接口 2.Cloneable对象只是一个标识对象, ...

  6. if判断与比较操作符gt、lt、eq等的使用

    在整数中比较使用如下  //-eq 等于(equal) if [ "$a" -eq "$b" ] //-ne不等于(no equal) if [ "$ ...

  7. IntelliJ IDEA使用(一)基本设置与类、方法模板设置

    其实之前一直开发都是在使用的是Eclipse,但是最近在做Maven项目的时候要用IntelliJ IDEA,据说这个idea功能非常的强大,最近在使用的时候发现如果适应的真的是非常的强大.感觉是比E ...

  8. OSI与TCP/IP网络模型分层

      学习linux的人,都会接触到一些网络方面的知识.作为一个linux方面的萌新,今天,小编就接触了OSI模型和TCP/IP协议栈,那么什么是OSI模型呢?     OSI模型,开放式系统互联通信参 ...

  9. linux模拟实现主机跨路由通信

    p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; text-align: justify; f ...

  10. PHP初入,(特效的使用)

    <body> <input id="btn1" type="button" value="按钮" /> <in ...