题目链接:

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. VC,一条会被鼠标移动的直线

    对话框中的小红线可以被移动的 一.类名是 CBinarizationDlg 二.定义两个变量BOOL m_flag;int nPos;在构造函数初始化m_flag = false;nPos=256;三 ...

  2. Main Memory Object-Relational Database Management System

    Main Memory Object-Relational Database Management System FastDBMain Memory Relational Database Manag ...

  3. java entry

    我希望要一个ArrayList<Entry>,类似C++中的pair, 可是Map.Entry是个接口,不能实例化,能够像以下这样写 HashMap<Integer, Integer ...

  4. Struts2获取演示示例教程

    回想Struts2的使用过程,网上搜的教程多多少少都会有点问题.又一次记录下创建过程,方便查阅. 1.下载Struts2的jar包 下载地址:http://archive.apache.org/dis ...

  5. LVS Nginx HAProxy 优缺点

    搭建负载均衡高可用环境相对简单,主要是要理解其中原理.此文描述了三种负载均衡器的优缺点,以便在实际的生产应用中,按需求取舍. 目前,在线上环境中应用较多的负载均衡器硬件有F5 BIG-IP,软件有LV ...

  6. 14.4.4 Configuring the Memory Allocator for InnoDB InnoDB 配置内存分配器

    14.4.4 Configuring the Memory Allocator for InnoDB InnoDB 配置内存分配器 当InnoDB 被开发, 内分配齐 提供了与操作系统和运行库往往缺乏 ...

  7. 新发现IM项目Rabbitim(使用msys或者cygwin编译安装),FileZilla(wxWidget开发)

    https://github.com/KangLin/rabbitim/blob/master/docs/INSTALL.md https://github.com/KangLin/rabbitim ...

  8. HashMap的工作原理(转)

    HashMap的工作原理是近年来常见的Java面试题.几乎每个Java程序员都知道HashMap,都知道哪里要用HashMap,知道Hashtable和HashMap之间的区别,那么为何这道面试题如此 ...

  9. HP MSA2312 ERROR

    司在用的hp MAS2312存储其中一台每天都会报一个错误 EVENT:Vdisk verification failed. Command failed. (error code: 1) 2 err ...

  10. ubuntu12.04下搭建ftpserver

    楼主想把同学硬盘里面的200多G电影共享给实验室的小伙伴们看,就打算在内网server上搭建一个ftp的server. 1.安装ftp 首先在终端下键入例如以下内容,安装ftpserver: sudo ...