1. #include "iostream"
  2. #include "algorithm"
  3. #include "cstdio"
  4. using namespace std;
  5. const int maxn=;
  6. typedef struct
  7. {
  8. int a,b,v,c;
  9. }node;
  10. int ans;
  11. node graph[maxn*(maxn-)/];
  12. int father[maxn];
  13. int Find(int x)
  14. {
  15. if(father[x]==x)
  16. return x;
  17. else
  18. {
  19. father[x]=Find(father[x]);
  20. return father[x];
  21. }
  22. }
  23. void Union(int a,int b,int v,int c)
  24. {
  25. if(Find(a)!=Find(b))
  26. {
  27. ans+=v;
  28. father[Find(a)]=Find(b);
  29. }
  30. }
  31. bool cmp(node a,node b)
  32. {
  33. return a.v<b.v;
  34. }
  35. int main()
  36. {
  37. int N,M;
  38. while(~scanf("%d",&N)){
  39. if(N==)
  40. break;
  41. M=N*(N-)/;
  42. ans=;
  43. for(int i=;i<M;i++)
  44. {
  45. scanf("%d%d%d%d",&graph[i].a,&graph[i].b,&graph[i].v,&graph[i].c);
  46. if(graph[i].c==)
  47. graph[i].v=;
  48. }
  49. for(int i=;i<maxn;i++)
  50. father[i]=i;
  51. sort(graph,graph+M,cmp);
  52. for(int i=;i<M;i++)
  53. Union(graph[i].a,graph[i].b,graph[i].v,graph[i].c);
  54. printf("%d\n",ans);
  55. }
  56. return ;
  57. }

HDU 1879(最小生成树)的更多相关文章

  1. hdu 1879 继续畅通工程

    /************************************************************************/ /* hdu 1879 继续畅通工程 Time L ...

  2. HDU 1233(最小生成树)

    HDU 1233(最小生成树 模板) #include <iostream> #include <algorithm> #include <cstdio> usin ...

  3. hdu 1879 继续通畅工程(最小生成树)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1879 /************************************************* ...

  4. hdu 1879 继续畅通工程 (并查集+最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1879 继续畅通工程 Time Limit: 2000/1000 MS (Java/Others)    ...

  5. (step6.1.1)hdu 1879(继续畅通工程——最小生成树、kruscal)

    题目大意:输入一个整数n,表示有n个村庄.在接下来的n(n-1)/2行中,每行有4个整数begin  end  weight  flag.分别表示从begin到end之间可以连通 ,他们之间的费用为w ...

  6. hdu 1879 继续畅通工程 (最小生成树)

    继续畅通工程 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. hdu 1879 继续畅通工程(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algo ...

  8. HDU 1879 继续畅通工程(最小生成树)

    省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经 ...

  9. HDU 1879 还是prim最小生成树、

    #include<stdio.h> #include<math.h> #include<string.h> +,MAX=1e7; int vis[qq]; int ...

随机推荐

  1. [luoguP1011] 车站(递推)

    传送门 蒟蒻我关系式没有找出来. 直接模拟递推过程好了. 代码 #include <cstdio> #define N 21 int a, n, m, x, y; int up[N][2] ...

  2. topcoder SRM 639 div2

    见这里 http://ygdtc.sinaapp.com/?p=257

  3. mysql 之 Workbench的使用

    mysql 之 Workbench的使用 (1)简介 MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具.它是著名的数据库设计工具DBDesigner4的继任者.你可以用My ...

  4. codeforces 691E(矩阵乘法)

    E. Xor-sequences time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  5. Layui颜色

    Layui颜色 视觉疲劳的形成往往是由于颜色过于丰富或过于单一形成的麻木感,而 layui 提供的颜色,清新而不乏深沉,互相柔和,不过分刺激大脑皮层的神经反应,形成越久越耐看的微妙影像.合理搭配,可与 ...

  6. php配置(php7.3)

    [PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; PHP's initialization file, general ...

  7. GNS3模拟的硬件

    Hardware emulated by GNS3 Cisco 1700 Series 1700s have one or more interfaces on the motherboard, 2 ...

  8. [Spring] Bean Scope Singleton cs Prototype

    We can define a class to be Singleton or Prototype. If the class was defined as Prototype, then ever ...

  9. 通过android XML 创建图形,降低对美工的依赖

    在开发中总会须要自己定义各种View的样式,假设总是依赖美工作图弄出须要的UI样式图片(比方:一个button要选中和默认两张图片),不但时间上会浪费.往往也会有适配问题. 尽管能够通过.9图来解决一 ...

  10. Mariadb 主从

    一 mariadb主从多用于网站架构,因为该主从的同步机制是异步的,数据的同步有一定延迟,也就是说有可能会造成数据的丢失,但是性能比较好,因此网站大多数用的是主从架构的数据库,读写分离必须基于主从架构 ...