#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(最小生成树)的更多相关文章

  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. [luoguP1019] 单词接龙(DFS)

    传送门 不知为什么,判断全部包含反而A不了,不判断反而A了,╮(╯▽╰)╭ 代码 #include <cstdio> #include <iostream> #define m ...

  2. [K/3Cloud] 隐藏菜单后,如何在插件间接的调用隐藏菜单的操作

    使用场景: 动态表单里面挂了个单据的序时薄,序时薄有菜单,但是把序时薄的工具栏隐藏了.新增,修改全部动态表单自己写.删除和过滤我想间接调用下隐藏的序时薄的删除和过滤按钮的操作.在插件里如何实现? 答: ...

  3. 【ZJOI2017 Round1练习&BZOJ5350】D5T1 masodik(DP,斜率优化)

    题意:你要从(0,0)点走到(n,m), 每次只能往 x 轴或者 y 轴正方向移动一个单位距离.从(i,j)移动到(i,j+1)的代价为 ri,从(i,j)移动到(i+1,j)的代价为 cj. 求最小 ...

  4. msp430入门学习13

    msp430的定时器--Timer_B(定时器B)

  5. Ubuntu 16.04出现chmod: 无效模式:"a"的问题解决

    命令: chmod a+x file1 提示:注意文件的类型,如果用在文件夹上是不行的,但是文件确实可以的.

  6. Node.js安装及环境配置之Windows篇(转:https://www.cnblogs.com/zhouyu2017/p/6485265.html)

    Node.js安装及环境配置之Windows篇(原文地址:https://www.cnblogs.com/zhouyu2017/p/6485265.html)   一.安装环境 1.本机系统:Wind ...

  7. mongodb的备忘录

    https://www.cnblogs.com/best/p/6212807.html

  8. UVA - 11374 Airport Express (Dijkstra模板+枚举)

    Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express ...

  9. python3 使用http.server模块 搭建一个简易的http服务器

    from http.server import HTTPServer, BaseHTTPRequestHandler import json data = {'result': 'this is a ...

  10. Android默认系统声音/大小修改及配置【转】

    本文转载自:http://blog.csdn.net/a8316124/article/details/60574859 在做定制需求的时候,需要修改系统通知的声音,将其禁用掉,避免第三方应用发送通知 ...