HDU1879最小生成树 通畅工程
来源:互联网 发布:秋风知落叶 编辑:程序博客网 时间:2024/05/17 21:07
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct Road{ int c1,c2,cost,done;}road[5051];int father[110];int cmp(const Road a,const Road b){ return a.cost<b.cost;}int find(int x){ if(father[x]==-1) return x; return father[x]=find(father[x]);}int merge(int a,int b){ int x=find(a); int y=find(b); if(x==y)return 0; if(x>y)father[x]=y; else father[y]=x; return 1;}int main(){ int n,m,count,sum,i; while(scanf("%d",&n)&&n){ sum=0; count=0; memset(father,-1,sizeof(father)); m=n*(n-1)/2; for(i=1;i<=m;i++){ scanf("%d%d%d%d",&road[i].c1,&road[i].c2,&road[i].cost,&road[i].done); if(road[i].done&&merge(road[i].c1,road[i].c2)) count++; } sort(road+1,road+m+1,cmp); for(i=1;i<=m;i++){ if(merge(road[i].c1,road[i].c2)&&road[i].done==0){ count++; sum+=road[i].cost; } if(count==n-1) break; } printf("%d\n",sum); } return 0;}
0 0
- HDU1879最小生成树 通畅工程
- HDU1879--继续通畅工程--最小生成树--并查集
- Hdu1879 - 继续畅通工程 - 最小生成树
- hdu1879 继续畅通工程 最小生成树
- hdu1233 - 还是通畅工程(最小生成树)
- HDU1875 通畅工程再续 最小生成树
- hdoj 1875 通畅工程再续 最小生成树
- [HDU](1233)还是通畅工程 ---最小生成树(图)
- 最小生成树 克丽丝卡尔算法 hdu1879 继续畅通工程
- hdu1879继续畅通工程 最小生成树prim算法
- hdu1879继续畅通工程 最小生成树prim算法
- hdu1879 继续畅通工程 (最小生成树之prim 算法)
- hdu1879 继续畅通工程(最小生成树)
- HDU1879 继续畅通工程 【最小生成树Prim】
- hdu1879(Kruskal最小生成树)--继续畅通工程
- hdu1879 继续畅通工程(最小生成树、 并查集)
- hdu1879 继续畅通工程(最小生成树)
- hdu1879 继续畅通工程 (kruskal求最小生成树)
- Python内置函数学习(5)-bin(x)
- JAVA进阶案例 TCP编程之网络聊天工具(服务端)
- 有向无环图及其在汉语分词中的应用
- linux网络编程之socket(一):socket概述和字节序、地址转换函数
- Xutil使用时出现arg0.reslut或responseInfo.result问题
- HDU1879最小生成树 通畅工程
- HDU1898
- HDU 2014
- extern与头文件(*.h)的区别和联系
- ubuntu怎样通过终端打开firefox?
- USB 隨身碟容量變小恢復原本容量的解決方法
- 在Activity中使用Menu
- PHP的几种常见的加密技术
- Hibernate(1)——总体概述