HDU 3108 Ant Trip
Ant Trip
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3524 Accepted Submission(s):
1393
connecting the towns.
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.
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.
to form to achieve their goal.
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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,tot,ans;
int vis[];
int fa[],num[];
int into[],du[];
int find(int x){
if(fa[x]==x) return fa[x];
else return fa[x]=find(fa[x]);
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
tot=;ans=;
memset(du,,sizeof(du));
memset(vis,,sizeof(vis));
memset(num,,sizeof(num));
memset(into,,sizeof(vis));
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
into[x]++;into[y]++;
int dx=find(x);int dy=find(y);
if(dx!=dy) fa[dy]=dx;
}
for(int i=;i<=n;i++){
int now=find(i);
if(!vis[now]){
vis[now]=;
num[++tot]=now;
}
if(into[i]%!=) du[now]++;
}
for(int i=;i<=tot;i++){
if(into[num[i]]==) continue;
if(du[num[i]]==) ans++;
ans+=du[num[i]]/;
}
cout<<ans<<endl;
}
}
HDU 3108 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条边的无向图,求用几笔可以把所有边画完(画过的边 ...
- 一本通1530 Ant Trip
1530:Ant Trip [题目描述] 原题来自:2009 Multi-University Training Contest 12 - Host by FZU 给你无向图的 N 个点和 M 条边, ...
- HDU3018: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) ...
随机推荐
- Java web开发中主要用到的jar包
1.Java开发中主要用到的jar包介绍:(1)java JDK基础开发包:java包和javax包.书写方式:import java.lang.reflect.InvocationTargetExc ...
- Windows下面使用curl
Windows下面使用curl 学习了:https://www.cnblogs.com/xing901022/p/4652624.html 下载地址:https://curl.haxx.se/down ...
- SQL学习之使用order by 依照指定顺序排序或自己定义顺序排序
我们通常须要依据客户需求对于查询出来的结果给客户提供自己定义的排序方式,那么我们通常sql须要实现方式都有哪些,參考很多其它资料总结例如以下(不完好的和错误望大家指出): 一.假设我们仅仅是对于在某个 ...
- Yocto tips (19): Yocto SDK Toolchian的使用
在使用之前须要先source env,导入各种环境变量(注意将路径变更成你自己的): source ../qt5_sdk/environment-setup-cortexa9hf-vfp-neon-p ...
- poj 2777 Count Color(线段树、状态压缩、位运算)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38921 Accepted: 11696 Des ...
- USACO 5.1.1凸包
转自:http://blog.csdn.net/cnyali/article/details/50097593 程序: #include <iostream> #include <a ...
- leetcode第一刷_Add Binary
二进制相加,本质上就是大整数加法,有关大整数加法我的舍友教过我一个非常好的方法,先用一个int数组保存结果,将两个数相应位置相加,所有加完后.再统一处理进位的问题.这种方法相同适用于大整数的乘法. 这 ...
- Creating new web parts kentico 10
Developing web parts https://docs.kentico.com/k10/custom-development/developing-web-parts Web parts ...
- Service Mesh(服务网格)
Service Mesh(服务网格) 什么是Service Mesh(服务网格)Service mesh 又译作 "服务网格",作为服务间通信的基础设施层.Buoyant 公司的 ...
- (五)api网关服务 zuul-路由
路由是微服务架构中必须的一部分,比如,“/” 可能映射到你的WEB程序上,”/api/users “可能映射到你的用户服务上,“/api/shop”可能映射到你的商品服务商.(注解:我理解这里的这几个 ...