HDU3018 几笔画(非1笔)
Ant Trip
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2010 Accepted Submission(s): 782
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<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int father[maxn];
int indegree[maxn];
int n,m;
int a[maxn];
void init(){
for(int i=;i<=n;i++)
father[i]=i;
}
int find(int u){
if(father[u]!=u)
father[u]=find(father[u]);
return father[u];
}
void Union(int x,int y){
int t1=find(x);
int t2=find(y);
if(t1!=t2)
father[t1]=t2;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
init();
// memset(father,0,sizeof(father));
memset(indegree,,sizeof(indegree));
memset(a,-,sizeof(a));
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
indegree[u]++;
indegree[v]++;
Union(u,v);
} for(int i=;i<=n;i++){
int t=find(i);
if(a[t]==-&&indegree[i]>)
a[t]=;
if(indegree[i]&)
a[t]++;
}
int ans=;
for(int i=;i<=n;i++){
if(a[i]==)
ans++;
else if(a[i]>)
ans+=a[i]/;
}
printf("%d\n",ans);
}
return ;
}
HDU3018 几笔画(非1笔)的更多相关文章
- hdu3018 一笔画问题
题意: 给你一幅画,这幅画由点和边构成,问你最少几笔能把这幅画画完. 思路: 这个题目的结论比较巧妙,首先我们考虑下,如果给的图是欧拉图,或者是条欧拉回路,那么我们一笔就搞定了, ...
- nyoj-----42一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- 23个适合logo设计的常用英文字体
在很多国外的品牌中我们都会发现他们的英文字体在logo的运用中,不仅会提升logo的品质还会让logo看起来更加美观.今天我们就来看看都有哪些常常出现在logo设计中的英文字体吧. 字体,与文字本 ...
- [No0000A9]实用word用法
目录 TOC \o "1-3" \h \z \u 三招去掉页眉那条横线.... PAGEREF _Toc465252982 \h 08D0C9EA79F9BACE118C8200 ...
- Blue Path(基于cocos2dx 3.0)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=498 iTunes下载:http ...
- zw字王《中华大字库》2018版升级项目正式启动
zw字王<中华大字库>2018版升级项目正式启动 https://www.cnblogs.com/ziwang/p/9500537.html 这次升级是和字库协会一起合作,首批推出的字体, ...
- 一本通1530 Ant Trip
1530:Ant Trip [题目描述] 原题来自:2009 Multi-University Training Contest 12 - Host by FZU 给你无向图的 N 个点和 M 条边, ...
- Ant Trip HDU - 3018(欧拉路的个数 + 并查集)
题意: Ant Tony和他的朋友们想游览蚂蚁国各地. 给你蚂蚁国的N个点和M条边,现在问你至少要几笔才能所有边都画一遍.(一笔画的时候笔不离开纸) 保证这M条边都不同且不会存在同一点的自环边. 也就 ...
- 预备作业02 : 体会做中学(Learning By Doing)
1.你有什么技能比大多人(超过班级90%以上)更好? 如果说不算上玩玻璃球在诸如此类不登大雅之堂的技能,我想我是没有什么比大多数人更好的.我的兴趣还算广泛,但很多东西也只是学到了皮毛而已. 在我上初中 ...
随机推荐
- Sentinel spring-cloud-gateway adapter(1.6)异常错误之@EnableCircuitBreaker
sentinal 大坑 使用gateway adaper包出现@EnableCircuitBreaker did you forget include starter的异常 这时候千万不要学我引入cl ...
- bzoj4622 [NOI 2003] 智破连环阵
Description B国在耗资百亿元之后终于研究出了新式武器——连环阵(Zenith Protected Linked Hybrid Zone).传说中,连环阵是一种永不停滞的自发性智能武器.但经 ...
- Dynamic typing 动态类型
https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/Dyna ...
- 复习C++_基础、函数、数组、字符串
程序的开发过程 程序 源程序:用源语言写的,有待翻译的程序: 目标程序:源程序通过翻译程序加工以后生成的机器语言程序: 可执行程序:连接目标程序以及库中的某些文件,生成的一个可执行文件,例如Windo ...
- python_72_json序列化2
#序列化(json是最正规的) import json info={ 'name':'Xue Jingjie', 'age':22 } f=open('第72.text','w') print(jso ...
- 转:Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
转自:http://blog.csdn.net/business122/article/details/7536991 创建列表 sample_list = ['a',1,('a','b')] Pyt ...
- JDBC 基本语法总结
实现JDBC操作: 静态SQL执行 ① 注册驱动 Class.forName("com.mysql.jdbc.Driver"); ② 创建连接 Connection con = D ...
- SQL Server数据库日志清除
第一步 将数据库转换成 simple 模式 USE master GO ALTER DATABASE 所要删除日志的数据库名 SET RECOVERY SIMPLE WITH NO_WAIT GO 第 ...
- vue项目跨域问题
跨域 了解同源政策:所谓"同源"指的是"三个相同". 协议相同 域名相同 端口相同 解决跨域 jsonp 缺点:只能get请求 ,需要修改B网站的代码 cors ...
- 【Ecshop】后台菜单与权限管理
主要php文件: 1,admin/includes/inc_menu.php ECSHOP管理中心菜单数组--配置菜单组及URL 2,languages/zh_cn/admin/common.php ...