POJ 1789
来源:互联网 发布:域名转出收费吗 编辑:程序博客网 时间:2024/05/17 06:12
尚在调试中。。。。。
#include<cstdio>#include<iostream>#include<cstdlib>using namespace std;struct node{ int x,y,len;}e[1000];int f[100]={0},n,m,k,sum;int cmp(const void *x,const void *y){ return (*(struct node *)x).len-(*(struct node *)y).len;}int getf(int v){ if(f[v]==v) return v; else { f[v]=getf(f[v]); return f[v]; }}void merge(int v,int u){ if( getf(f[v]) != getf(f[u]) ) f[f[u]]=f[v];}int query(int v,int u){ if(getf(v)==getf(u)) return 1; else return 0;}int main(){ int i,x,y; while(scanf("%d",&n) && n) { for(i=1;i<=n;i++) qsort(&e[1],m,sizeof(e[0]),cmp); for(i=1;i <= n;i++) f[i]=i; i=1;k=0;sum=0; while(k < n) { if( query(e[i].x,e[i].y)==0 ) { k++; sum += e[i].len; merge(e[i].x,e[i].y); } i++; } printf("%d",sum); return 0; }}
- POJ 1789
- POJ 1789
- poj 1789
- poj 1789
- POJ 1789
- poj 1789
- POJ 1789
- POJ 1789
- poj.1789
- POJ 1789
- poj-1789
- poj 1789
- poj 1789
- POJ 1789
- poj 1789
- POJ-1789
- POJ 1789
- POJ 1789
- .tar.bz2的解压方法
- 操作系统
- 从QProcess说开来(二)
- POJO
- ubuntu开机自动挂载Windows分区硬盘 用ntfs-config
- POJ 1789
- 如何快速的学习ssh框架
- Android中Bitmap、Drawable、byte[]转换
- 小技巧:双击Office工具栏可隐藏工具条
- 异步IO网络服务器设计(二) 读操作
- iOS5编程--官方例子代码研究--5.TableMultiSelect
- 回调函数
- CXF 简单教程初级版
- POJ 3615