Poj 3723 Conscription -- 最大生成树(森林)
来源:互联网 发布:aim聊天软件申请 编辑:程序博客网 时间:2024/04/28 04:25
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;struct edge{int a,b;int d;}r[50010];int p[20010];int root(int x){if(p[x]==x)return p[x];return p[x] = root(p[x]);}void merge(int a,int b){a = root(a);b = root(b);p[a] = b;}bool cmp(edge a,edge b){return a.d>b.d;}int main(){int t;int girl,boy,n,ans;scanf("%d",&t);while(t--){scanf("%d%d%d",&girl,&boy,&n);for (int i = 0; i < n; i++){scanf("%d%d%d",&r[i].a,&r[i].b,&r[i].d);r[i].b += girl; }for (int i = 0; i < boy+girl; i++){p[i] = i;}sort(r,r+n,cmp);int minus = 0;for (int i = 0; i < n; i++){if(root(r[i].a) != root(r[i].b)){merge(r[i].a,r[i].b);minus += r[i].d; }}ans = 10000*(girl+boy);ans -= minus;printf("%d\n",ans);}return 0;}
- POJ 3723 Conscription(最大生成森林)
- Poj 3723 Conscription -- 最大生成树(森林)
- poj 3723 Conscription 【最大生成树|最大权森林】
- POJ 3723 Conscription 【最大生成树||最大权森林】
- POJ 3723 Conscription (kruskal最大生成森林)
- POJ 3723 Conscription(最大生成树)
- poj 3723 Conscription(最大生成树)
- POJ 3723 Conscription(最大生成树)
- poj-3723 Conscription 最大生成树
- POJ 3723 Conscription (最大生成树)
- POJ--3723---Conscription---最大生成树
- poj 3723 Conscription(最大生成树)
- POJ 3723 Conscription【最大生成树】
- POJ-3723-Conscription最大生成树
- POJ 3723 - Conscription(最大生成树)
- POJ 3723 conscription 最大生成树
- Conscription poj 3723最大生成树
- poj 3723 Conscription(最大生成树 kruscal)
- 实例化Spring Ioc容器,生成SequenceGenerator
- Java程序员推荐书目
- sql总结
- ORACLE10G手工创建数据库非ASM
- Android实现删除apk弹出网页
- Poj 3723 Conscription -- 最大生成树(森林)
- windows server2003 bugzilla 安装心得
- BeanFactory与ApplicationContext的区别
- WARNING: Can't find the Qt version that's associated with this project.
- LeetCode - Valid Parentheses
- 无法打开文件“opencv_calib3d240d.lib”
- Android入门--文件的基本输入输出流,读写文件的方法实现
- JavaScript Source Map 详解
- hdu 1815 网络流寻找字典序最小割集 好题