题目链接:

Ant Trip

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 32768/32768 K (Java/Others)

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.

 
题意:
 
就是给你无向图,问多少笔能把这些边都画完,所以孤立的点不用管;
 
思路:
 
NND ,一开始bfs写的有问题,我还以为有什么WA点,就在网上找题解,我擦,TMD全都是并查集,而且代码都一样,真想说一句去他大爷的;
最后发现vis的位置不能乱放;
bfs找到的一个连通块中,如果是一个欧拉回路ans+1,如果里面有奇度的点,那么肯定是成对出现的,因为一条边对应两个点的度,那么一次可以选一对奇度的点为起始点和终止点,那么这个连通块的答案就是这个连通块中奇度点的个数/2;
 
 
AC代码
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+;
const ll mod=1e9+;
int n,m,vis[N],ind[N],u,v;
vector<int>ve[N];
queue<int>qu;
int bfs(int num)
{
int cnt=;
qu.push(num);
vis[num]=;
while(!qu.empty())
{
int fr=qu.front();
qu.pop();
if(ind[fr]%==)cnt++;
int len=ve[fr].size();
for(int i=;i<len;i++)
{
int y=ve[fr][i];
if(!vis[y])
{
vis[y]=;
qu.push(y);
}
}
}
return cnt;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)
{
ind[i]=vis[i]=;
ve[i].clear();
}
for(int i=;i<m;i++)
{
scanf("%d%d",&u,&v);
ve[u].push_back(v);
ve[v].push_back(u);
ind[u]++;
ind[v]++;
}
for(int i=;i<=n;i++)
{
if(ind[i]==)vis[i]=;
}
int ans=;
for(int i=;i<=n;i++)
{
if(!vis[i])
{
int s=bfs(i);
if(s==)ans++;
else ans+=s/;
}
}
printf("%d\n",ans); }
return ;
}

hdu-3018 Ant Trip(欧拉路径)的更多相关文章

  1. [欧拉回路] hdu 3018 Ant Trip

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) ...

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

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

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

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

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

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

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

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

  6. HDU 3018 Ant Trip

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

  7. HDU 3108 Ant Trip

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

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

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

  9. HDU 3018 欧拉回路

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

随机推荐

  1. 【Todo】Java并发学习 & 示例练习及代码

    接上一篇:http://www.cnblogs.com/charlesblc/p/6097111.html <Java并发学习 & Executor学习 & 异常逃逸 & ...

  2. editplus重新载入文档

    editplus重新载入文档 :document->reload

  3. XmlNode与XmlElement的区别总结

    原文链接:http://www.cnblogs.com/oilsun/archive/2012/07/07/2580427.html 今 天在做ASP.NET操作XML文档的过程中,发现了两个类:Xm ...

  4. C++ ADO 连接 mysql

    1.安装mysql-5.0.22-win32,mysql-connector-odbc-5.1.12-win32.msi    然后:开始菜单->设置->控制面板->管理工具-> ...

  5. visual c++ 2013进行MySQL编程(ODBC) -- (一) 套装安装

    最近写了有些技术类文章了,只因为最近研究多了些东西,有一些项目用到了,所以自己记录一下,怕自己忘记,如果有哪位同学有自己的见解,可以邮件或者回复,技术类的探讨,不管对否,都是欢迎的. 操作之前,必须安 ...

  6. sql语言复习2

    一.查询 select 字段列表 from 表名列表 [where 条件表达式][group by 字段列表[having 条件表达式]] [order by 字段列表[asc|desc]] 含义:在 ...

  7. mysql生产环境____主从同步修复案例

    一.   硬件环境 Master: Dell R720 Intel(R)Xeon(R) CPU E5-2640 v2 @ 2.00GHz MEM 64G.disk 4*2.5 SAS  网络4* 千兆 ...

  8. mysql 执行sql文件的方法

     http://philos.iteye.com/blog/162051   实战代码: #mysql导入mysql -um4n -p01D060A476642BA8335B832AC5B211F22 ...

  9. PHP中curl获取本机虚拟主机接口

    在PHP的curl代码中增加header可解决此问题. $header = array( "Host: 你的域名(不能包含http://)", "Accept: text ...

  10. vmware克隆一台机器后修改etho

    1 vi /etc/udev/rules.d/70-persistent-net.rules 2 注释NAME="eth0"的内容 3 将NAME="eth1" ...