题意:

  Ant Tony和他的朋友们想游览蚂蚁国各地。

给你蚂蚁国的N个点和M条边,现在问你至少要几笔才能所有边都画一遍.(一笔画的时候笔不离开纸) 
保证这M条边都不同且不会存在同一点的自环边. 
也就是蚂蚁分组遍历整个无向图,他们试图把所有的人分成几个小组,每个小组可以从不同的城镇开始。 
Tony想知道最少需要几组。 

Input输入包含多组测试用例,由多个空行分隔。 
每个测试用例的第一行是两个整数N(1<=N<=100000)、M(0<=M<=200000),表明蚂蚁国有N个城镇和M条道路。 
在M条线路之后,每条线路包含两个整数u,v,(1<=u,v<=N,表示有一条道路连接城镇u和城镇v。 
Output对于每个测试用例,输出需要形成的最少组数来实现它们的目标。Sample Input

  1. 3 3
  2. 1 2
  3. 2 3
  4. 1 3
  5.  
  6. 4 2
  7. 1 2
  8. 3 4

Sample Output

  1. 1
  2. 2
  3.  
  4. 解析:
      题中没有保证所有的点都是一个连通块,所以对于每个连通块,都有三种情况
     1、当前连通块每个点的度数都为偶数,即为欧拉回路 所以一笔就行
     2、有 x 个奇点,已知每两个奇点可以组成一条欧拉路径,所以 笔画数 = x / 2
    3 单个点成为连通块 那么0
    用并查集维护连通块就好了
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <sstream>
  4. #include <cstring>
  5. #include <map>
  6. #include <cctype>
  7. #include <set>
  8. #include <vector>
  9. #include <stack>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <bitset>
  14. #define rap(i, a, n) for(int i=a; i<=n; i++)
  15. #define rep(i, a, n) for(int i=a; i<n; i++)
  16. #define lap(i, a, n) for(int i=n; i>=a; i--)
  17. #define lep(i, a, n) for(int i=n; i>a; i--)
  18. #define rd(a) scanf("%d", &a)
  19. #define rlld(a) scanf("%lld", &a)
  20. #define rc(a) scanf("%c", &a)
  21. #define rs(a) scanf("%s", a)
  22. #define pd(a) printf("%d\n", a);
  23. #define plld(a) printf("%lld\n", a);
  24. #define pc(a) printf("%c\n", a);
  25. #define ps(a) printf("%s\n", a);
  26. #define MOD 2018
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define Pair pair<int, int>
  30. #define mem(a, b) memset(a, b, sizeof(a))
  31. #define _ ios_base::sync_with_stdio(0),cin.tie(0)
  32. //freopen("1.txt", "r", stdin);
  33. using namespace std;
  34. const int maxn = 1e6 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
  35. int deg[maxn], f[maxn], cnt[maxn];
  36. set<int> g;
  37. int find(int x)
  38. {
  39. return f[x] == x ? x : (f[x] = find(f[x]));
  40. }
  41.  
  42. int main()
  43. {
  44. int n, m;
  45. while(cin >> n >> m)
  46. {
  47. for(int i = ; i <= n; i++) f[i] = i;
  48. mem(deg, );
  49. mem(cnt, );
  50. g.clear();
  51. int u, v;
  52. for(int i = ; i <= m; i++)
  53. {
  54. cin >> u >> v;
  55. int l = find(u);
  56. int r = find(v);
  57. if(l != r) f[l] = r;
  58. deg[u]++;
  59. deg[v]++;
  60. }
  61. for(int i = ; i <= n; i++)
  62. {
  63. int x = find(i);
  64. if(deg[i] & ) cnt[x]++;
  65. g.insert(x);
  66. }
  67. int res = ;
  68. for(set<int>::iterator it = g.begin(); it != g.end(); it++)
  69. {
  70. int x = *it;
  71. if(deg[x] == ) continue;
  72. if(cnt[x] == ) res++;
  73. else res += cnt[x] / ;
  74. }
  75. cout << res << endl;
  76.  
  77. }
  78.  
  79. return ;
  80. }
  1.  

Ant Trip HDU - 3018(欧拉路的个数 + 并查集)的更多相关文章

  1. Day4 - K - Ant Trip HDU - 3018

    Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together with his fr ...

  2. hdoj 3018 Ant Trip(无向图欧拉路||一笔画+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 思路分析:题目可以看做一笔画问题,求最少画多少笔可以把所有的边画一次并且只画一次: 首先可以求出 ...

  3. hdu 5458 Stability(树链剖分+并查集)

    Stability Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total ...

  4. [HDU 3712] Fiolki (带边权并查集+启发式合并)

    [HDU 3712] Fiolki (带边权并查集+启发式合并) 题面 化学家吉丽想要配置一种神奇的药水来拯救世界. 吉丽有n种不同的液体物质,和n个药瓶(均从1到n编号).初始时,第i个瓶内装着g[ ...

  5. hdu 5833(欧拉路)

    The Best Path Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  6. HDU 5458 Stability (树链剖分+并查集+set)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 给你n个点,m条边,q个操作,操作1是删边,操作2是问u到v之间的割边有多少条. 这题要倒着做才 ...

  7. HDU 1232 畅通工程(模板——并查集)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1232 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出 ...

  8. HDU 3172 Virtual Friends (map+并查集)

    These days, you can do all sorts of things online. For example, you can use various websites to make ...

  9. HDU - 1272 小希的迷宫 【并查集】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 思路 只需要判断 这张图 无环 并且只有一个连通块 就可以了 要注意 如果 只输入 0 0 那给 ...

随机推荐

  1. BZOJ3720 Gty的妹子树 询问分块、主席树

    传送门 学到了询问分块的科技-- 对于修改操作,每发生了\(S\)次修改就重构整棵树,小于\(S\)次的修改操作丢到一个队列里面. 对于每一次查询操作,先在主席树上查询当前子树内部大于\(k\)的节点 ...

  2. 在平衡树的海洋中畅游(一)——Treap

    记得有一天翔哥毒奶我们: 当你们已经在平衡树的海洋中畅游时,我还在线段树的泥沼中挣扎. 我觉得其实像我这种对平衡树一无所知的蒟蒻也要开一开数据结构了. 然后花了一天啃了下最简单的平衡树Treap,感觉 ...

  3. [Socket]Socket聊天小程序

    一个简单是Socket聊天小程序,读写操作在不同的线程中.服务器端采用线程池. 1.Server import java.io.IOException; import java.net.ServerS ...

  4. Mysql8.0的登录大坑……(忘记登录密码也可以这么搞)

    关于安装和使用就不说了,属于基本操作了: 我来重点记录一下关于使用前,使用navicat登录的时候报错,1130和2059 查看安装后随机生成的密码: grep 'temporary password ...

  5. 自己动手写把”锁”---LockSupport深入浅出

    本篇是<自己动手写把"锁">系列技术铺垫的最后一个知识点.本篇主要讲解LockSupport工具类,它用来实现线程的挂起和唤醒. LockSupport是Java6引入 ...

  6. 基于HTML5 Canvas的工控SCADA模拟飞机飞行

    昨天看到一篇文章说是学习如何开飞机的,然后我就想,如果我也可以开飞机那就好玩了,每个人小时候都想做飞行员!中国飞行员太难当了,再说也不轻易让你开飞机!后来我就想如果能用 HT 开飞机那就是真的有趣了, ...

  7. Thrift_简介(基于C#)

    //Server: TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true, true); TTransportFact ...

  8. MySQL高可用架构-MMM环境部署记录

    MMM介绍MMM(Master-Master replication manager for MySQL)是一套支持双主故障切换和双主日常管理的脚本程序.MMM使用Perl语言开发,主要用来监控和管理 ...

  9. 解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file

    原文地址:http://blog.csdn.net/yjk13703623757/article/details/53217377 一.问题 运行hydra时,提示错误: hydra : error ...

  10. CentOS 6.7下 Samba服务器的搭建与配置(share共享模式)

    https://www.linuxidc.com/Linux/2016-12/138220.htm