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) ...
随机推荐
- crm 系统项目(一) 登录,注册,校验
crm 系统项目(一) 登录,注册,校验 首先创建一个Django项目,关于配置信息不多说,前面有~ models.py文件下创建需要的表格信息,之后导入数据库 from django.db impo ...
- Linux5355端口被0.0.0.0监听
Linux后台有个systemd-resolv进程,占用5355等端口 博主在一次网络安全加固行动中,netstat -anp发现Linux后台有一个被0.0.0.0监听的端口,5355,显示被sys ...
- ASP.NET-HttpPostedFileBase file为null的问题
MVC使用Ajax.BeginForm上传图片时HttpPostedFileBase file为null,Request.Files获取不到文件,问题分析是页面中存在jquery.unobtrusiv ...
- Oracle 实现 mysql 更新 update limit
oracle给人的感觉非常落后.使用非常不方便,Toad 这个软件又笨又迟钝.pl/sql更是,90年代的界面风格,速度还卡得要死.并且oracle不支持limit .by default7#zbph ...
- java大数类,两个不超过20位都不为0的十进制字符串相乘,华为笔试题
import java.math.BigInteger; import java.util.*; import java.io.*; public class Main { public static ...
- hdoj--1260--Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- flex布局下img变形的问题
flex-shrink 加上:flex-shrink:0:定义了缩小比例,默认为1,即如果空间不足,项目将会缩小所有项目为1时,空间不足,都会缩小,如果你不希望某个容器在任何时候都不被压缩,那设置f ...
- JS循环 for while 全局/局部变量 短路
循环语句: For for循环的格式 for(var i = 0; i < 10; i ++){ } for循环的执行顺序: ① ② 若判断为 true 进④ 进③ 进②判断 ……循环 ...
- matlab张量工具初步
最近从桑迪亚实验室下载了张量工具包.但是不太会用. 很多网上的方法, addpath(pwd) cd met; addpath(pwd) savepath M=ones(4,3,2); X=tenso ...
- Python3.x和Python2.x的区别(转存参考)
http://www.360doc.com/content/14/0619/23/16740871_388198818.shtml 这个星期开始学习Python了,因为看的书都是基于Python2.x ...