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 ...
随机推荐
- [K/3Cloud] 单据新增、复制、新增行、复制行的过程
整单复制:先执行CopyData(获得数据包),在执行AfterCreateNewData(可处理数据包),不会执行AfterCreateNewEntryRow 单据新增:先执行AfterCreate ...
- 【NOIP2017练习】怎样打好隔膜(贪心,堆,带删除priority_queue)
题意:OI大师抖儿在夺得银牌之后,顺利保送pku.这一天,抖儿问长者:“我的手速虽然已经站在了人类的巅峰,但是打隔膜还是输.我换了很多队友,但是没有用.请问应该怎样打好隔膜?”长者回答:“你啊,Too ...
- SharedPreferences保存用户偏好参数
package com.example.administrator.myapplication; import android.content.Context; import android.cont ...
- <项目><day11>查看用户浏览过的商品
<项目>查看用户浏览过的商品 1.创建一个entity包储存实体对象 1.1创建一个Product的类存储实体对象 对象具有以下属性,并添加set和get方法,含参和不含参的构造方法,to ...
- yum install tree 出错primary.sqlite.bz2: [Errno -1] Metadata file does not match checks 解决办法
Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfilehttp://ftp.sjtu.edu.cn/centos ...
- rsyslog trouble shooting
openstack,swift的log不输出了.trouble shooting过程 , 发现我们的程序 /var/log/swift/proxy.log等总是不输出log. 因为log rsyslo ...
- laravel5.4新特性
http://www.cnblogs.com/webskill/category/1067140.html laravel 5.4 新特性 component and slot 使用: 1.compo ...
- 制作svg动画
要实现一步一步画出来一个图片,css3做不到吧.除非一张张的图片定时显示.想不到别的招了.如今用的是一个插件,做了一个svg动画. 插件地址:http://lazylinepainter.info/ ...
- windows server 证书的颁发与IIS证书的使用 Dapper入门使用,代替你的DbSQLhelper Asp.Net MVC中Action跳转(转载)
windows server 证书的颁发与IIS证书的使用 最近工作业务要是用服务器证书验证,在这里记录下一. 1.添加服务器角色 [证书服务] 2.一路下一步直到证书服务安装完成; 3.选择圈选 ...
- 【面试】iOS 开发面试题(一)
1. #import 跟#include 又什么差别,@class呢, #import<> 跟 #import""又什么差别? 答:#import是Objectiv ...