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 ...
随机推荐
- Nginx+Keepalived实现 转载
一.Keepalived简介 keepalived是一个类似于layer3, 4 & 5交换机制的软件,也就是我们平时说的第3层.第4层和第5层交换.Keepalived的作用是检测web服务 ...
- 使用MeanJS Yeoman Generator
1.首先全局安装该生成器 sudo npm install -g generator-meanjs 2.为项目创建一个路径 mkdir xmen && cd xmen 3.创建app ...
- 使用PHP flush 函数的时候我们需要注意些什么呢?
WebServer(可以认为特指apache)的缓冲区.在apache module的sapi下, flush会通过调用sapi_module的flush成员函数指针,间接的调用apache的api: ...
- HDU 3966:Aragorn's Story(树链剖分)
http://acm.hdu.edu.cn/showproblem.php?pid=3966 题意:有n个点n-1条边,每个点有一个权值,有两种操作:询问一个点上权值是多少和修改u到v这条链上的权值. ...
- SQL基础教程
第一范式: 列仅包含原子值: 没有重复的组. 第二范式: 满足第一范式: 非部分函数依赖.(如果组合键中任何一列值改变,将导致非键列的值需要被更新) 那么,主键是一列(不是组合的)满足第二范式:所有列 ...
- C# 加密解密
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Secur ...
- Wormholes 分类: POJ 2015-07-14 20:21 21人阅读 评论(0) 收藏
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35235 Accepted: 12861 Descr ...
- PL/SQL注册码
code:j6stndb9tk72xfbhbqczcdqnjd8lyj466n number:882851 ps:xs374ca
- HDU(1856),裸的带权并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856 题意:朋友圈问题,A和B是朋友,B和C是朋友则A和C也是朋友,依次类推,题目的意思就是求最大的朋 ...
- Android Https
/** * HttpUrlConnection支持所有Https免验证,不建议使用 * * @throws KeyManagementException * @throws NoSuchAlgorit ...