HDU 1879(最小生成树)
- #include "iostream"
- #include "algorithm"
- #include "cstdio"
- using namespace std;
- const int maxn=;
- typedef struct
- {
- int a,b,v,c;
- }node;
- int ans;
- node graph[maxn*(maxn-)/];
- int father[maxn];
- int Find(int x)
- {
- if(father[x]==x)
- return x;
- else
- {
- father[x]=Find(father[x]);
- return father[x];
- }
- }
- void Union(int a,int b,int v,int c)
- {
- if(Find(a)!=Find(b))
- {
- ans+=v;
- father[Find(a)]=Find(b);
- }
- }
- bool cmp(node a,node b)
- {
- return a.v<b.v;
- }
- int main()
- {
- int N,M;
- while(~scanf("%d",&N)){
- if(N==)
- break;
- M=N*(N-)/;
- ans=;
- for(int i=;i<M;i++)
- {
- scanf("%d%d%d%d",&graph[i].a,&graph[i].b,&graph[i].v,&graph[i].c);
- if(graph[i].c==)
- graph[i].v=;
- }
- for(int i=;i<maxn;i++)
- father[i]=i;
- sort(graph,graph+M,cmp);
- for(int i=;i<M;i++)
- Union(graph[i].a,graph[i].b,graph[i].v,graph[i].c);
- printf("%d\n",ans);
- }
- return ;
- }
HDU 1879(最小生成树)的更多相关文章
- hdu 1879 继续畅通工程
/************************************************************************/ /* hdu 1879 继续畅通工程 Time L ...
- HDU 1233(最小生成树)
HDU 1233(最小生成树 模板) #include <iostream> #include <algorithm> #include <cstdio> usin ...
- hdu 1879 继续通畅工程(最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1879 /************************************************* ...
- hdu 1879 继续畅通工程 (并查集+最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1879 继续畅通工程 Time Limit: 2000/1000 MS (Java/Others) ...
- (step6.1.1)hdu 1879(继续畅通工程——最小生成树、kruscal)
题目大意:输入一个整数n,表示有n个村庄.在接下来的n(n-1)/2行中,每行有4个整数begin end weight flag.分别表示从begin到end之间可以连通 ,他们之间的费用为w ...
- hdu 1879 继续畅通工程 (最小生成树)
继续畅通工程 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 1879 继续畅通工程(最小生成树,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algo ...
- HDU 1879 继续畅通工程(最小生成树)
省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经 ...
- HDU 1879 还是prim最小生成树、
#include<stdio.h> #include<math.h> #include<string.h> +,MAX=1e7; int vis[qq]; int ...
随机推荐
- [luoguP1011] 车站(递推)
传送门 蒟蒻我关系式没有找出来. 直接模拟递推过程好了. 代码 #include <cstdio> #define N 21 int a, n, m, x, y; int up[N][2] ...
- topcoder SRM 639 div2
见这里 http://ygdtc.sinaapp.com/?p=257
- mysql 之 Workbench的使用
mysql 之 Workbench的使用 (1)简介 MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具.它是著名的数据库设计工具DBDesigner4的继任者.你可以用My ...
- codeforces 691E(矩阵乘法)
E. Xor-sequences time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- Layui颜色
Layui颜色 视觉疲劳的形成往往是由于颜色过于丰富或过于单一形成的麻木感,而 layui 提供的颜色,清新而不乏深沉,互相柔和,不过分刺激大脑皮层的神经反应,形成越久越耐看的微妙影像.合理搭配,可与 ...
- php配置(php7.3)
[PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; PHP's initialization file, general ...
- GNS3模拟的硬件
Hardware emulated by GNS3 Cisco 1700 Series 1700s have one or more interfaces on the motherboard, 2 ...
- [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 ...
- 通过android XML 创建图形,降低对美工的依赖
在开发中总会须要自己定义各种View的样式,假设总是依赖美工作图弄出须要的UI样式图片(比方:一个button要选中和默认两张图片),不但时间上会浪费.往往也会有适配问题. 尽管能够通过.9图来解决一 ...
- Mariadb 主从
一 mariadb主从多用于网站架构,因为该主从的同步机制是异步的,数据的同步有一定延迟,也就是说有可能会造成数据的丢失,但是性能比较好,因此网站大多数用的是主从架构的数据库,读写分离必须基于主从架构 ...