最小生成树 POJ3723 Conscription
来源:互联网 发布:淘宝联盟app推广 编辑:程序博客网 时间:2024/06/05 22:38
题目大意:给出n1个女孩子和n2个男孩子之间的关系。你要把他们全部加入你的军队,求一个最小花费。
题目意思我说不清,大概就是最小生成树啦,不过我们要使这个生成树的权值最大,是一个最大生成树。
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#define Maxn 22000#define Maxm 60000#define INF 0x3f3f3f3fusing namespace std;struct Edge{int u,v,len;}edge[Maxm];int fa[Maxn];int n1,n2,m;int getfather(int x){if (x!=fa[x]) return fa[x]=getfather(fa[x]);return fa[x];}int Kruskal(){int ret=0;for (int i=0;i<=n1+n2;i++) fa[i]=i;for (int i=1;i<=m;i++){int u=getfather(edge[i].u);int v=getfather(edge[i].v);if (u==v) continue;fa[v]=u;ret+=edge[i].len;}return ret;}bool cmp(Edge a,Edge b){return a.len>b.len;}int main(){int cases,u,v,len;;scanf("%d",&cases);while (cases--){scanf("%d%d%d",&n1,&n2,&m);for (int i=1;i<=m;i++){scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].len);edge[i].v+=n1;}sort(edge+1,edge+m+1,cmp);printf("%d\n",10000*(n1+n2)-Kruskal());}return 0;}
0 0
- [POJ3723] Conscription [最小生成树]
- 最小生成树 POJ3723 Conscription
- poj3723 Conscription(最小生成树)
- POJ3723 Conscription , 最大权森林问题 ->最小生成树问题
- poj Kruskal 【poj3723 Conscription : 最大生成树;poj 1251 Jungle Roads: 最小生成树poj1861Network】
- poj3723最小生成树
- Conscription 最小生成树
- POJ3723 Conscription 解题报告【Kruskal/最大生成树】
- Conscription (最小生成树)
- POJ3723 Conscription
- POJ3723-Conscription
- poj3723 Conscription
- poj3723 Conscription
- poj3723 Conscription
- poj3723 Conscription
- poj3723 Conscription Kruscal算法最大生成森林
- POJ3723 招募士兵[最小生成树]
- poj 3723 Conscription ---最小生成树
- Lua的debug hook功能探究与改造--上篇 . http://blog.csdn.net/soloist/article/details/1458743
- 内存泄漏原因
- cocos2d-x之浅析Hello World
- ASP.NET MVC 描述类型(二)
- Effective Java (6) 消除过期的对象引用
- 最小生成树 POJ3723 Conscription
- LAMP安装问题
- 初探Linux网络协议栈
- HDU 1203 I NEED A OFFER!(01背包基础题)
- 腾讯后台面试
- POJ3045 Cow Acrobats 二分搜索
- spring mvc 基础配置
- 数字图像处理
- tty设备驱动数据流动分析