POJ 3723 Conscription
来源:互联网 发布:淘宝卖阿迪达斯的店铺 编辑:程序博客网 时间:2024/06/05 14:35
Description
Windy has a country, and he wants to build an army to protect his country. He has picked upN girls and M boys and wants to collect them to be his soldiers. To collect a soldier without any privilege, he must pay 10000 RMB. There are some relationships between girls and boys and Windy can use these relationships to reduce his cost. If girl x and boy y have a relationship d and one of them has been collected, Windy can collect the other one with 10000-d RMB. Now given all the relationships between girls and boys, your assignment is to find the least amount of money Windy has to pay. Notice that only one relationship can be used when collecting one soldier.
Input
The first line of input is the number of test case.
The first line of each test case contains three integers, N, M andR.
Then R lines followed, each contains three integers xi,yi and di.
There is a blank line before each test case.
1 ≤ N, M ≤ 10000
0 ≤ R ≤ 50,000
0 ≤ xi < N
0 ≤ yi < M
0 < di < 10000
Output
Sample Input
25 5 84 3 68311 3 45830 0 65920 1 30633 3 49751 3 20494 2 21042 2 7815 5 102 4 98203 2 62363 1 88642 4 83262 0 51562 0 14634 1 24390 4 43733 4 88892 4 3133
Sample Output
7107154223
题目大意:大佬要挑n个女生和m个男生到他的军队里面,每挑到一个人,就要给人家10000RMB,如果女孩x与男孩y有关系d且他们其中一个被招了,那么招另外一个就只用支付10000-d RMB了,算出最少的费用
最小生成树,用的是Kruskal算法
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int n,m,r;int tree[20010];struct Node{int u,v,w;}map[50010];bool cmp(Node a,Node b){return a.w>b.w;}int find(int x){return x==tree[x]?x:tree[x]=find(tree[x]);}int main(){int t;scanf("%d",&t);while(t--){cin>>n>>m>>r;for(int i=0;i<=n+m;i++) tree[i]=i;int kount=0;while(r--){int x,y,z;scanf("%d%d%d",&x,&y,&z);map[kount].u=x;map[kount].v=y+n;map[kount++].w=z;}sort(map,map+kount,cmp);int sum=(n+m)*10000;for(int i=0;i<kount;i++){int a=find(map[i].u);int b=find(map[i].v);if(a!=b){sum-=map[i].w;tree[a]=b;}}printf("%d\n",sum);}return 0;}
- poj 3723 Conscription
- POJ 3723 Conscription
- POJ 3723 Conscription
- POJ-3723-Conscription
- POJ 3723 Conscription
- POJ 3723 Conscription MST
- 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 3723Conscription
- POJ 3723 Conscription
- Conscription POJ - 3723
- POJ 3723 Conscription
- 【AC自动机-fail树+离线+DFS序+树状数组】BZOJ2434(Noi2011)[阿狸的打字机]题解
- SpringBoot的RabbitMQ消息队列: 三、第二模式"Work queues"
- Vue常用经典开源项目汇总参考-海量
- JS中函数之外不能写return
- shell中 单引号、双引号、无引号、反斜杠在grep命令中的二次转义
- POJ 3723 Conscription
- @Transaction注解的理解以及手动回滚事务的2种方法
- oracle字段Varchar2长度问题
- jquery 用creatjs preloadjs的方法
- JavaEE面试题库分类及答案之六
- 数据结构封装之《GTree通用树》
- Eclipse中查看Class文件源码——Jad插件安装与配置
- 最简单的IOS
- 2-sat