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) ...
随机推荐
- linux 源码包安装拾遗
源码包安装和apt-get/yum的区别 安装前的区别:概念上的区别 rpm和dpkg包是经过编译过的包,并且其安装位置由厂商说了算,厂商觉得安装在哪里合适,就会装在哪里,而源码包则是没有经过编译的文 ...
- Linux150个命令
命令 功能说明 线上查询及帮助命令(2个) man 查看命令帮助,命令的词典,更复杂的还有info,但不常用. help 查看Linux内置命令的帮助,比如cd命令. 文件和目录操作命令(18个) l ...
- python_字典的使用
'''info = { "stu1":"Lie","stu2":"Weite","stu3":&qu ...
- VUE:计算属性和监视
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Vue基础操作
一.Vue入门基础知识 1.Vue使用的基本操作 i. 先下载,引入vue.jsii. Vue,实例化一个vue实例化对象(new Vue({})) 1. 新建一个vue实例化对象(Vue是一个构造函 ...
- git 简单理解
现在git这个版本控制大行其道,弄了半天大概理解了一下他的工作原理. 使用流程 1,安装git ,小乌龟,小乌龟汉化(在设置里面第一项,检查更新,下载中文包安装) 2,设置 小乌龟 ->git ...
- codevs 1803 志愿者招募
1803 志愿者招募 2008年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 申奥成功后,布布经过不懈努 ...
- Oracle expdp导出多表或表中的部分数据
http://blog.itpub.net/16582684/viewspace-755072/
- Tomcat远程代码执行漏洞(CVE-2017-12615)修复
一.漏洞介绍 2017年9月19日,Apache Tomcat官方确认并修复了两个高危漏洞,其中就有Tomcat远程代码执行漏洞,当存在漏洞的Tomcat运行在Windwos主机上,且启用了HTTP ...
- JAVA学习之 异常处理机制
今天就来说说java的异常处理机制,异常处理不是第一接触,尤其是写过非常多c#的代码,基本都会写到异常处理的代码,事实上c#的异常处理与java的异常处理基本都是一样的,仅仅是在一些细节上不是非常一样 ...