博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3018 Ant Trip
阅读量:6296 次
发布时间:2019-06-22

本文共 2600 字,大约阅读时间需要 8 分钟。

Ant Trip

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2960    Accepted Submission(s): 1188

Problem Description
Ant Country consist of N towns.There are M roads 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.
 

 

Input
Input 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.
 

 

Output
For each test case ,output the least groups that needs to form to achieve their goal.
 

 

Sample Input
3 3
1 2
2 3
1 3
 
4 2
1 2
3 4
Sample Output
1
2
--------------------------------------------------------------------------------------------手动分割线--------------------------------------------------------------------------------------------------------
题目大意:
  给你N个点并且他们之间的路径,问你最少要画几笔才能经过全部边。
  第一行包括两个数N,M(N表示点的个数,M表示路径数)
  接下来是M行,每一行包括两个数a,b表示a,b之间有路径。
  最后输出要画几笔。(注意有多组输入数据)
大致思路:
  先用并查集判断图中有几个联通块,对于每个联通块,判断其中的点的度,如果其中点的度都是偶数,那么便存在欧拉回路,只用画一笔,如果是奇数,则要画该联通块中奇数的个数/2笔。
代码附上:
1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 #define N 100006 7 int fa[N]; 8 int du[N]; 9 int vis[N];10 int ji[N];11 vector
q;12 void init(int n)13 {14 for(int i=0;i<=n;i++)15 {16 fa[i]=i;17 }18 memset(du,0,sizeof(du));19 memset(vis,0,sizeof(vis));20 memset(ji,0,sizeof(ji));21 q.clear();22 }23 int myfind(int x)24 {25 if(fa[x]!=x)26 {27 fa[x]=myfind(fa[x]);28 }29 return fa[x];30 }31 void hebing(int x,int y)32 {33 x=myfind(x);34 y=myfind(y);35 if(x!=y)36 {37 fa[y]=x;38 }39 }40 int main()41 {42 int n,m;43 while(scanf("%d%d",&n,&m)!=EOF)44 {45 int a,b;46 init(n);47 int ans=0;48 for(int i=0;i

 

转载于:https://www.cnblogs.com/xxjnoi/p/7193589.html

你可能感兴趣的文章
MacOS High Sierra 12 13系统转dmg格式
查看>>
关于再次查看已做的多选题状态逻辑问题
查看>>
动态下拉菜单,非hover
查看>>
政府安全资讯精选 2017年第十六期 工信部发布关于规范互联网信息服务使用域名的通知;俄罗斯拟建立备用DNS;Google打击安卓应用在未经同意情况下收集个人信...
查看>>
简单易懂的谈谈 javascript 中的继承
查看>>
iOS汇编基础(四)指针和macho文件
查看>>
Laravel 技巧锦集
查看>>
Android 使用 ViewPager+RecyclerView+SmartRefreshLayout 实现顶部图片下拉视差效果
查看>>
Flutter之基础Widget
查看>>
写给0-3岁产品经理的12封信(第08篇)——产品运营能力
查看>>
ArcGIS Engine 符号自动化配置工具实现
查看>>
小程序 · 跳转带参数写法,兼容url的出错
查看>>
flutter error
查看>>
Flask框架从入门到精通之模型数据库配置(十一)
查看>>
10年重新出发
查看>>
2019年-年终总结
查看>>
聊聊elasticsearch的RoutingService
查看>>
让人抓头的Java并发(一) 轻松认识多线程
查看>>
从源码剖析useState的执行过程
查看>>
地包天如何矫正?
查看>>