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.
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.
1 2
2 3
1 3
4 2
1 2
3 4
2
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;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9;
const ll INF=1e18+;
int n,m;
int fa[N],du[N],flag[N],mark[N],hh[N];
int Find(int x)
{
return fa[x]==x?x:fa[x]=Find(fa[x]);
}
void update(int u,int v)
{
int x=Find(u);
int y=Find(v);
if(x!=y)
{
fa[x]=y;
}
}
void init()
{
for(int i=;i<N;i++)
fa[i]=i;
memset(flag,,sizeof(flag));
memset(du,,sizeof(du));
memset(mark,,sizeof(mark));
memset(hh,,sizeof(hh));
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
init();
for(int i=;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
update(u,v);
du[u]++;
du[v]++;
hh[u]=;
hh[v]=;
}
int ans=,sum=;
for(int i=;i<=n;i++)
{
if(!hh[i])continue;
int x=Find(i);
du[i]%=;
sum+=du[i];
if(!flag[x])
{
ans++;
flag[x]=;
}
if(du[i]==&&flag[x]&&!mark[x])
{
ans--;
mark[x]=;
}
}
printf("%d\n",ans+sum/);
}
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 (并查集求连通块数+欧拉回路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 题目大意:有n个点,m条边,人们希望走完所有的路,且每条道路只能走一遍.至少要将人们分成几组. ...
- 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 ...
- hdu3018 Ant Trip (并查集+欧拉回路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 题意:给你一个图,每条路只能走一次.问至少要多少个人才能遍历所有的点和所有的边. 这是之前没有接 ...
- HDU 3018 Ant Trip
九野的博客,转载请注明出处: http://blog.csdn.net/acmmmm/article/details/10858065 题意:n个点m条边的无向图,求用几笔可以把所有边画完(画过的边 ...
- 【HDOJ3018】【一笔画问题】【欧拉回路+并查集】
http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) Me ...
- hdu 1116 欧拉回路+并查集
http://acm.hdu.edu.cn/showproblem.php?pid=1116 给你一些英文单词,判断所有单词能不能连成一串,类似成语接龙的意思.但是如果有多个重复的单词时,也必须满足这 ...
- HDU 1116 Play on Words(欧拉回路+并查集)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1116 Play on Words Time Limit: 10000/5000 MS (Java/Ot ...
随机推荐
- linux端口
1.查看开放的端口 netstat -anp 来查看哪些端口被打开. 注:加参数'-n'会将应用程序转为端口显示,即数字格式的地址,如:nfs->2049, ftp->21,因此可以开启两 ...
- PHP开发框架Laravel优点,Laravel5.3中文文档
PHP开发框架Laravel优点 Laravel的设计思想是很先进的,非常适合应用各种开发模式TDD, DDD和BDD,作为一个框架,它为你准备好了一切,composer是个php的未来,没有comp ...
- Intel+Ardruino 101
为了传说中的那啥, 啊, 嗯.. #include <CurieBLE.h>const int ledPin = 13; // set ledPin to on-board LED LE ...
- Linux驱动学习笔记(6)信号量(semaphore)与互斥量(mutex)【转】
转自:http://blog.chinaunix.net/uid-24943863-id-3193530.html 并发导致竟态,从而导致对共享数据的非控制访问,产生非预期结果,我们要避免竟态的发生. ...
- Temporary TempDB Tables [AX 2012]
Temporary TempDB Tables [AX 2012] 1 out of 4 rated this helpful - Rate this topic Updated: November ...
- 修改Linux时间一般涉及到3个命令: date, clock, hwclock
原贴:http://203.208.37.104/search?q=cache:p1vAAHvs9ikJ:www.goldthe.com /blog/%3Faction%3Dshowlog%26gid ...
- Oracle将表keep到内存
一.引言: 有时候一些基础表需要非常的频繁访问,尤其是在一些循环中,对该表中的访问速度将变的非常重要.为了提高系统的处理性能,可以考虑将一些表及索引读取并保存到内存中. 二.关于keep内存的几个参数 ...
- PHP文件系统处理相关操作
<?php/* PHP文件系统处理 * 所有文件处理都是使用系统函数完成的. * 是基于Linux/Unix系统为模型 * * 文件系统处理的作用: * 1. 所有的项目离不开文件处理 * 2. ...
- 修改ECSHOP系统红包序列号规律
ECSHOP系统线下发放红包时系统生成的红包序列号是在10000的基础上增加四位随机数字.如果当我们要发放大额度红包的时候,这样的序列号规则难免给人不安全的感觉,万一真的有哪个无聊的人,用一天时间来蒙 ...
- var_dump(is_writeable(ini_get("session.save_path")));
var_dump(is_writeable(ini_get("session.save_path")));