题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3018

Ant Trip

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1658    Accepted Submission(s): 641

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 
 

Statistic | Submit | Discuss | Note

题目意思:

给一幅无向图,求要用多少次一笔画,把全部边走完,边仅仅能走一次。孤立点不算。

解题思路:

dfs把每一个连通块找到,然后统计奇数度数节点个数。

注意孤立节点不算。

代码:

//#include<CSpreadSheet.h>

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; #define Maxn 110000
int de[Maxn],n,m;
vector<vector<int> >myv;
int in[Maxn],cnt;
bool vis[Maxn]; void dfs(int cur)
{
in[++cnt]=cur;
vis[cur]=true;
for(int i=0;i<myv[cur].size();i++)
{
int ne=myv[cur][i];
if(vis[ne])
continue;
dfs(ne);
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d%d",&n,&m))
{
myv.clear();
myv.resize(n+10);
memset(de,0,sizeof(de)); for(int i=1;i<=m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
myv[a].push_back(b);
myv[b].push_back(a);
de[a]++;
de[b]++;
}
memset(vis,false,sizeof(vis)); int ans=0; for(int i=1;i<=n;i++)
{
if(!vis[i])
{
cnt=0;
dfs(i);
int temp=0;
if(cnt==1) //孤立节点不算
continue;
for(int j=1;j<=cnt;j++)
{
if(de[in[j]]&1)
temp++;
//printf("i:%d j")
}
if(!temp)
ans++;
else
ans+=temp/2;
}
}
printf("%d\n",ans); }
return 0;
}

[欧拉回路] hdu 3018 Ant Trip的更多相关文章

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

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

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

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

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

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

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

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

  5. HDU 3018 Ant Trip

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

  6. HDU 3108 Ant Trip

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

  7. hdoj 3018 Ant Trip(无向图欧拉路||一笔画+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 思路分析:题目可以看做一笔画问题,求最少画多少笔可以把所有的边画一次并且只画一次: 首先可以求出 ...

  8. HDU 3018 欧拉回路

    HDU - 3018 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together ...

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

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

随机推荐

  1. 多校 4686 Arc of Dream hdu 矩阵解

    构造矩阵如下: Ai*bi AX*BX AX*BY AY*BX AY*BY 0 a(i-1)*b(i-1) Ai 0 AX 0 AY 0 a(i-1) Bi 0 0 BX BY 0 b(i-1) 1 ...

  2. Windbg抓取程序崩溃的dmp文件的方法

    Windbg抓取程序崩溃的dmp文件的方法 一.        简介 windbg是在windows平台下,强大的用户态和内核态调试工具.相比较于Visual Studio,它是一个轻量级的调试工具, ...

  3. Linux程序设计学习笔记----多线程编程线程同步机制之相互排斥量(锁)与读写锁

    相互排斥锁通信机制 基本原理 相互排斥锁以排他方式防止共享数据被并发訪问,相互排斥锁是一个二元变量,状态为开(0)和关(1),将某个共享资源与某个相互排斥锁逻辑上绑定之后,对该资源的訪问操作例如以下: ...

  4. hnnu 11546 Sum of f(x) (求一个数的全部约数和)

    代码: #include<cstdio> #include<cstring> #define N 200000 using namespace std; long long f ...

  5. 设备管理 USB ID

    发现个USB ID站点,对于做设备管理识别的小伙伴特别实用 http://www.linux-usb.org/usb.ids 附录: # # List of USB ID's # # Maintain ...

  6. 在WIN7系统的笔记本上建立WIFI热点

        成功与否的关键在于你是否依照顺序运行:       前置条件:右键"我的电脑"--"属性"--"设备管理器"--"网络适配 ...

  7. 第二十次codeforces竞技结束 #276 Div 2

    真是状况百出的一次CF啊-- 终于还Unrated了,你让半夜打cf 的我们怎样释怀(中途茫茫多的人都退场了)--虽说打得也不好-- 在这里写一下这一场codeforces的解题报告.A-E的 题目及 ...

  8. WOJ 1055

    #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char s[6]={0} ...

  9. Python基础 - 迭代

    前言 在pythone中经常可以看到iterable这样的描述. 直译为迭代. 这是在C中没有的概念. iterable(可迭代) 支持每次返回自己所包含的一个成员的对象就是可迭代对象. iterab ...

  10. Android大图片导致内存问题小结

    在网上看了部分Android中OOM的问题,现在根据理解,做一下笔记. Android OOM 产生的几种原因 1. 程序中使用了太多自己创建的Bitmap. 这种情况通常是最好解决的. 因为你明白你 ...