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 ...
随机推荐
- arcgis andriod 加载影像
MapView mMapView;......String rasterPath = Environment.getExternalStorageDirectory().getPath() + &qu ...
- linux的history命令设置
history的历史记录,同一个用户的各个会话,读取到的内容也是不一样的,原因是它读取的是shell会话缓存里的内容.只有当用户退出当前会话的时候,会话里的缓存内容才会写入~/.bash_histor ...
- cug oj 1479 Treasure Chest Lock (区间dp 思维)
1479: Treasure Chest Lock Time Limit: 1 Sec Memory Limit: 128 MB Submit: 7 Solved: 5 [id=1479" ...
- Linux包括hash_map和hash_set的not declared问题
当在Linux下cpp文件包括hash_map或hash_set时.会出现"'hash_map' was not declared in this scope"问题. #inclu ...
- Odoo multiprocessing
Odoo 在 非 windows 系统下, 支持 并行处理,开启 workers 配置项 即可. odoo有以下配置项 跟 并行处理有关 配置项 帮助信息 解说 limit_memor ...
- dubbo学习之Hello world
现在企业中使用dubbo的越来越多,今天就简单的学习一下dubbo,写了一个hello world,教程仅供入门,如要深入学习请上官网 服务提供方: 首先将提供方和消费方都引入jar包,如果使用的是m ...
- x264 编码数配置
记录项目中用到一组x264快速编码参数配置,具体如下: param->i_frame_reference = 1; param->i_scenecut_threshold = 0; par ...
- php错误封装类
1.创建MyErrorHandler.php文件 代码如下: <?php class MyErrorHandler { public $message; public $filename; pu ...
- 在eclipse中查找指定文件 [多种方法]
在eclipse中查找指定文件 1.ctrl+h打开搜索界面 File Search: containing text填*,File name patterns填写hello.*,可以找到hell ...
- mysql 数据类型+约束+关联
1.什么是存储引擎存储引擎就是表的类型,针对不同的存储引擎,mysql会有不同的处理逻辑 2.存储引擎介绍InnoDB| DEFAULT | Supports transactions, row-le ...