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 ...
随机推荐
- uitableview中文排序问题
1,uitableview中涉及到排序的问题,查找资料后发现使用UILocalizedIndexedCollation可以很好处理中文和英文系统下中文的排序.而且如果第一个汉字首字母一样那么就会按照第 ...
- iOS开发 CGBitmapContextCreate
最近项目中,需要对图片进行各种操作. 使用CGBitmapContextCreate 创建位图上下文. CG_EXTERN CGContextRefCGBitmapContextCreate(void ...
- VC 读取服务器上的文件(HTTP方式) [转]
CString GetStringFromUrl(LPCTSTR pszUrl){ CString str ; HINTERNET hSession = ::InternetOpen( _ ...
- 【windows socket+UDPserverclient】
Windows Socket+UDPserverclient Winsock是 Windows下套接字标准. 1.UDP socket编程: ...
- 介绍一个开源的SIP(VOIP)协议库PJSIP
本文系转载,出处不可考. 假设你对SIP/VoIP技术感兴趣,哪希望你不要错过:),假设你对写出堪称优美的Code感兴趣 ,那么你也不可错过:) 这期间我想分析一下一个实际的协议栈的设计到实现的相关技 ...
- Selenium系列之--07 操作远程浏览器
Selenium远程控制浏览,可以通过如下两种方式实现,本质上都是Selenium Grid a. 客户机启Selenium Standalone Server 作为远程服务,服务端通过调用Remo ...
- yum安装nginx+PHP+Mysql
#mkdir /var/www/yum_repo 1.nginx安装: 在http://nginx.org/en/linux_packages.html#stable中下载CentOSX对应版本的rp ...
- git mirror的创建与使用
please donwload repo mirro as follow steps, thanks 1.mirror server,server IP:192.168.0.123 1.1 -- de ...
- MVC上传多张图片
改变上传文件的按钮样式: <div id="post-upload-image"> <div id="divfile_-1"> < ...
- nginx的源代码分析--间接回调机制的使用和类比
nginx使用了间接回调机制.结合upstream机制的使用来说明一下,首先明白几个事实: 1)事实上ngxin和下游client的连接使用的是ngx_http_connection_t,每一个连接相 ...