题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3018

题目:

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

Hint

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.

 
Source
  1. /*
  2. 问题 给出n个顶点和m条边,n<=100000,m<=200000,若要遍历所有的边且每条边只能走一次,问至少需要几个起点
  3. 保证没有重复道路,保证道路两端的城市是不同的,存在孤立的点,例如 3个点,1条边,1和2联通,那么3就是孤立的点
  4.  
  5. 解题思路 简单总结就是一笔画问题,画的时候,要么a--->b(一条线),即a和b均为奇点(度数为奇数的点),要么a--->a(一个圈),即该圈中没有奇点
  6. 由于连通图中不可能存在奇数个奇点,换句话说连通图中奇点要么不出现,即存在欧拉回路,只需要一笔,要么成对出现,每一对需要一笔
  7. 那么总的笔画数等于 所有奇点的个数除以2(孤立的点度数为0,为偶数) 加上 欧拉回路数
  8.  
  9. 输入时计算每个顶点的度数,使用并查集将图分成一块一块,遍历每一个顶点,找出奇点计数并且标记其根节点;再遍历顶点,
  10. 如果不是孤立的点 且 是根 且 该根没有被标记过,即为欧拉回路。
  11. */
  12. #include<stdio.h>
  13. #include<string.h>
  14. int deg[],fat[],book[];
  15. void merge(int a, int b);
  16. int getf(int x);
  17.  
  18. int main()
  19. {
  20. int n,m;
  21. int i,a,b;
  22. while(scanf("%d%d",&n,&m) != EOF)
  23. {
  24. memset(deg,,sizeof(deg));
  25. for(i=;i<=n;i++){
  26. fat[i]=i;
  27. }
  28. for(i=;i<=m;i++){
  29. scanf("%d%d",&a,&b);
  30. deg[a]++;
  31. deg[b]++;
  32. merge(a,b);
  33. }
  34.  
  35. memset(book,,sizeof(book));
  36. int singsum=;
  37. for(i=;i<=n;i++){
  38. if(deg[i] & ){
  39. book[ getf(i) ]=;//标记以该点为根的一块图中存在奇点
  40. singsum++;
  41. }
  42. }
  43.  
  44. int eulenum=;
  45. for(i=;i<=n;i++){
  46. if(deg[i] > && i==fat[i] && == book[i])//不是孤立的点 且 是根 且 该根没有被标记过,即是欧拉回路
  47. eulenum++;
  48. }
  49. printf("%d\n",singsum/+eulenum);
  50. }
  51. return ;
  52. }
  53. void merge(int a, int b)
  54. {
  55. int t1,t2;
  56. t1=getf(a);
  57. t2=getf(b);
  58. if(t1 != t2){
  59. fat[t2]=t1;
  60. }
  61. }
  62. int getf(int x)
  63. {
  64. return fat[x]==x ? x : fat[x]=getf(fat[x]);
  65. }
 

Ant Trip(区别于二分匹配中最小路径覆盖的一笔画问题)的更多相关文章

  1. HDU 3861--The King’s Problem【scc缩点构图 &amp;&amp; 二分匹配求最小路径覆盖】

    The King's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. HDU3335 Divisibility Dilworth定理+最小路径覆盖

    首先需要一些概念: 有向图,最小路径覆盖,最大独立集,Dilworth,偏序集,跳舞链(DLX).... 理解一: 对于DAG图,有:最大独立集=点-二分匹配数,二分匹配数=最小路径覆盖. 而无向图, ...

  3. HDU 4606 Occupy Cities (计算几何+最短路+二分+最小路径覆盖)

    Occupy Cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. POJ3020 Antenna Placement(二分图最小路径覆盖)

    The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...

  5. HDU 3861 The King’s Problem(强连通+二分图最小路径覆盖)

    HDU 3861 The King's Problem 题目链接 题意:给定一个有向图,求最少划分成几个部分满足以下条件 互相可达的点必须分到一个集合 一个对点(u, v)必须至少有u可达v或者v可达 ...

  6. 【网络流24题】 No.3 最小路径覆盖问题 (网络流|匈牙利算法 ->最大二分匹配)

    [题意] 给定有向图 G=(V,E).设 P 是 G 的一个简单路(顶点不相交) 的集合.如果 V 中每个顶点恰好在 P 的一条路上,则称 P 是 G 的一个路径覆盖. P 中路径可以从 V 的任何一 ...

  7. hdu 1853 Cyclic Tour (二分匹配KM最小权值 或 最小费用最大流)

    Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total ...

  8. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  9. HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)

    题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...

随机推荐

  1. power designer简单教程

    1.file->new model 2.根据菜单或功能模型新建physical diagram(当然也可以新建package) 选中项目,右键——>new ->physical di ...

  2. openstack手动安装

    安装文档: https://github.com/yongluo2013/osf-openstack-training/blob/master/installation/openstack-iceho ...

  3. 使用Code First建模自引用关系笔记

    原文链接 一.Has方法: A.HasRequired(a => a.B); HasOptional:前者包含后者一个实例或者为null HasRequired:前者(A)包含后者(B)一个不为 ...

  4. 深入解析SQL Server高可用镜像实现原理

    本文来自网易云社区 SQL Server 是windows平台.NET架构下标配数据库解决方案,与Oracle.MySQL共同构成了DB-Engines Ranking的第一阵营,在国内外企业市场中有 ...

  5. MariaDB 用户与权限管理(12)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  6. [JSOI2018]列队(主席树)

    跟上次那道列队不一样,但都是九条可怜...(吉老师太强了) 在主席树上统计答案,因为值域只有 \(10^6\) 甚至不用离散化... \(Code\ Below:\) #include <bit ...

  7. 08_python_文件操作

    一.初始文件操作 打开⽂件的⽅式: r, w, a, r+, w+, a+, rb, wb, ab, r+b, w+b, a+b 默认使⽤的是r(只读)模式 f = open("少妇嫩模.t ...

  8. 解决linux下source /etc/profile关闭终端失效问题

    本来想配置环境变量的,看网上和博客上很多说改/etc/profile,然后source /etc/profile之后就可以永久保存使环境变量生效,但是终端一关闭,就环境变量就失效了,其他终端也用不了. ...

  9. 基于alpine用dockerfile创建的ssh镜像

    1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...

  10. SQL Server —— 查询数据库、表、列等

    一.查询数据库(sys.databases —— select *from sys.databases where name='<数据库名>') select *from sys.data ...