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 ...
随机推荐
- [NOIP2006] 提高组 洛谷P1064 金明的预算方案
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N元钱就行”.今 ...
- Maven公共仓库/镜像站收集及使用技巧
查询: 1.http://search.maven.org/ 2.https://mvnrepository.com/ 3.https://maven-repository.com/ 4.(阿里云镜像 ...
- LENOVO System x3850 X6
http://appserver.lenovo.com.cn/Lenovo_Series_List.aspx?CategoryCode=A31B01
- mysql导入大型sql文件时注意事项
原文:http://blog.csdn.net/k21325/article/details/70808563 大型sql文件,需要在my.ini(windows)或者my.cnf(Linux)中设置 ...
- ORA-00942:表或视图不存在 低级错误一例
ORA-00942:表或视图不存在 低级错误一例 运行查询语句,报ORA-00942错误 检查后发现没有指定表的所属用户.加入用户.再次查询,查询正常,截图例如以下: *************** ...
- Android之——多线程下载演示样例
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46883927 一.概述 说到Android中的文件下载.Android API中明 ...
- mac中apache+mysql+php+phpMyAdmin配置备忘
Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Apache 运行PHP 安装MySQL 使用phpMyAdmin 配 ...
- linux下alias命令具体解释
linux下alias命令具体解释 用途说明 设置命令的别名.在linux系统中假设命令太长又不符合用户的习惯,那么我们能够为它指定一个别名. 尽管能够为命令建立"链接" 解决长文 ...
- centOS的联网问题
centOS连接了一个下午,没连上网络,隔了两天,又试了一下午才把网连上,一直查centOS的网络连接问题都搞不定,最后还是问了朋友怎么给虚拟机联网谈到虚拟网卡的问题.建议可以看看网络适配器,VMwa ...
- Android Studio 使用 SVN 必然遇到问题:commit ** File out of data 问题解决方法
转载请注明:http://blog.csdn.net/lrs123123/article/details/44829579 Android Studio 的使用已经越来越成为趋势.而结合版本号控制工具 ...