hdu-3018 Ant Trip(欧拉路径)
题目链接:
Ant Trip
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
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.
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.
#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(欧拉路径)的更多相关文章
- [欧拉回路] hdu 3018 Ant Trip
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 3018 Ant Trip 欧拉回路+并查集
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- HDU 3018 Ant Trip (欧拉回路)
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 3018 Ant Trip(欧拉回路,要几笔)
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 3018 Ant Trip (并查集求连通块数+欧拉回路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 题目大意:有n个点,m条边,人们希望走完所有的路,且每条道路只能走一遍.至少要将人们分成几组. ...
- HDU 3018 Ant Trip
九野的博客,转载请注明出处: http://blog.csdn.net/acmmmm/article/details/10858065 题意:n个点m条边的无向图,求用几笔可以把所有边画完(画过的边 ...
- HDU 3108 Ant Trip
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdoj 3018 Ant Trip(无向图欧拉路||一笔画+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 思路分析:题目可以看做一笔画问题,求最少画多少笔可以把所有的边画一次并且只画一次: 首先可以求出 ...
- HDU 3018 欧拉回路
HDU - 3018 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together ...
随机推荐
- spring aop提供了两种实现方式jdk和cglib
Spring AOP使用了两种代理机制:一种是基于JDK的动态代理:另一种是基于CGLib的动态代理.之所以需要两种代理机制,很大程度上是因为JDK本身只提供接口的代理,而不支持类的代理. Sprin ...
- MongoDb 判断字段长度比较好的方法
查询某字段长度超过一定长度时的方法, MongoDB中可能不好处理,一般这样: db.test.find({ $where:"this.F_DAQDATA.legnth>600&quo ...
- Engine中如何截取线上指定两点间的线段?
//调用 IPolyline newLine = GetSubCurve(polyline, p1, p2); ESRI.ArcGIS.Display.IScreenDisplay screenD ...
- 转置卷积&&膨胀卷积
Convolution arithmetic tutorial theano Convolution arithmetric github 如何理解深度学习中的deconvolution networ ...
- dom4j的xpath查找xml的指定节点
递归遍历所有节点http://blog.csdn.net/sidihuo/article/details/47318723 获取Document SAXReader saxReader = new S ...
- 设计模式之中介者模式(Mediator)摘录
23种GOF设计模式一般分为三大类:创建型模式.结构型模式.行为模式. 创建型模式抽象了实例化过程.它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而 ...
- OpenJDK 源码阅读之 LinkedList
概要 类继承关系 java.lang.Object java.util.AbstractCollection<E> java.util.AbstractList<E> java ...
- error MSB8011: 未能注冊输出。请尝试启用“逐用户重定向”
初试MFC就遇到困难了.vs2010创建一个MFC ActiveX控件项目. 什么都还没做呢,就出现故障了? 郁闷呀.! ! 1>C:\Program Files\MSBuild\Microso ...
- 使用EA生成多层次的代码框架
最近工作期间发现了一个非常棒的UML软件[Enterprise Architect UML 建模工具]简称EA,在该软件上绘制框架层面的类之间关系后,可以自动生成相关语言的代码. EA上目前支持的语言 ...
- python--网络编程--socket
网络通信标准---网络协议 互联网协议--osi七层协议 五层协议:应用层:应用层.表示层.会话层 传输层:传输层 网络层:网络层 数据链路层:数据链路层 物理层: ...