Conscription

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 13   Accepted Submission(s) : 6
Problem Description

Windy has a country, and he wants to build an army to protect his country. He has picked up N 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 and R.
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
For each test case output the answer in a single line.
 
Sample Input
2 5 5 8 4 3 6831 1 3 4583 0 0 6592 0 1 3063 3 3 4975 1 3 2049 4 2 2104 2 2 781 5 5 10 2 4 9820 3 2 6236 3 1 8864 2 4 8326 2 0 5156 2 0 1463 4 1 2439 0 4 4373 3 4 8889 2 4 3133
 
Sample Output
71071 54223
题解:
征兵:有n个女生,m个男生,其中每个人需要花费10000元。不过男生和女生之间有相互作用,可以降低费用。比如编号为1的女生和编号为1的男生之间有关系d,那么女生已经征兵结束后,男生只需10000-d即可入伍
kruskal算法,让男生直接+maxn就好;
代码:
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN=;
struct Node{
int s,e,c;
};
int cmp(Node a,Node b){
return a.c>b.c;
}
Node dt[MAXN*];
int pre[MAXN*];
int ans;
int find(int x){
return pre[x]= x==pre[x]?x:find(pre[x]);
}
void initial(){
memset(pre,-,sizeof(pre));
ans=;
}
void merge(Node a){
int f1,f2;
if(pre[a.s]==-)pre[a.s]=a.s;
if(pre[a.e]==-)pre[a.e]=a.e;
f1=find(a.s);f2=find(a.e);
if(f1!=f2){
pre[f1]=f2;
ans+=a.c;
}
}
int main(){int N,M,R,T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&N,&M,&R);
initial();
for(int i=;i<R;i++){
scanf("%d%d%d",&dt[i].s,&dt[i].e,&dt[i].c);
dt[i].e+=MAXN;
}
sort(dt,dt+R,cmp);
for(int i=;i<R;i++){
merge(dt[i]);
}
printf("%d\n",*(M+N)-ans);
}
return ;
}

Conscription的更多相关文章

  1. POJ 3723 Conscription 最小生成树

    题目链接: 题目 Conscription Time Limit: 1000MS Memory Limit: 65536K 问题描述 Windy has a country, and he wants ...

  2. POJ 3723 Conscription

    Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6325   Accepted: 2184 Desc ...

  3. Conscription poj3723(最大生成树)

    Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6870   Accepted: 2361 Desc ...

  4. POJ 3723 Conscription (Kruskal并查集求最小生成树)

    Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14661   Accepted: 5102 Des ...

  5. POJ3723 Conscription 【并检查集合】

    Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8071   Accepted: 2810 Desc ...

  6. 【POJ - 3723 】Conscription(最小生成树)

    Conscription Descriptions 需要征募女兵N人,男兵M人. 每招募一个人需要花费10000美元. 如果已经招募的人中有一些关系亲密的人,那么可以少花一些钱. 给出若干男女之前的1 ...

  7. Conscription(POJ 3723)

    原题如下: Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16584   Accepted: 57 ...

  8. MST:Conscription(POJ 3723)

      男女搭配,干活不累 题目大意:需要招募女兵和男兵,每一个人都的需要花费1W元的招募费用,但是如果有一些人之间有亲密的关系,那么就会减少一定的价钱,如果给出1~9999的人之间的亲密关系,现在要你求 ...

  9. poj - 3723 Conscription(最大权森林)

    http://poj.org/problem?id=3723 windy需要挑选N各女孩,和M各男孩作为士兵,但是雇佣每个人都需要支付10000元的费用,如果男孩x和女孩y存在亲密度为d的关系,只要他 ...

随机推荐

  1. docker文章

    https://training.docker.com/self-paced-training http://special.csdncms.csdn.net/BeDocker/ http://clo ...

  2. linux之SQL语句简明教程---SELECT

    SQL是用来做什么的呢?一个最常用的方式是将资料从数据库中的表格内选出.从这一句回答中,我们马上可以看到两个关键字: 从 (FROM) 数据库中的表格内 选出 (SELECT).(表格是一个数据库内的 ...

  3. 创立Est•Design华服高级成衣定制工作室 - 北京服装学院-莱佛士国际学院

    创立Est•Design华服高级成衣定制工作室 - 北京服装学院-莱佛士国际学院 创立Est•Design华服高级成衣定制工作室 创立Est•Design华服高级成衣定制工作室 童雪涛   " ...

  4. linux ar 命令的使用

    摘自http://blog.csdn.net/hxg130435477/article/details/8217247 用途说明 创建静态库.a文件.用C/C++开发程序时经常用到,但我很少单独在命令 ...

  5. Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array

    解题报告 http://blog.csdn.net/juncoder/article/details/38102391 对于给定的数组,取对数组中的一段进行翻转,问翻转后是否是递增有序的. 思路: 仅 ...

  6. Hibernate征途(二)之基础与核心

    根据我司优良传统,必然要由上向下.逐级深入,所以在钻到Hibernate细节之前,先从宏观上行欣赏一下Hibernate.为什么说是欣赏?大家可以自行查阅一下Hibernate知识外的信息,创始人和H ...

  7. Banner 切换

    在线项目 :  Banner 切换 时间 : 2个小时 (15:00 - 17:00)满分 : 100分------------------------------------------------ ...

  8. pixel像素与物理像素

  9. SQL 时间格式化函数

    1 取值后格式化 {0:d}小型:如2005-5-6 {0:D}大型:如2005年5月6日 {0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中 ...

  10. Android应用开发基本流程及测试运行

    (1)Android App工程项目的创建 File—New—New Project 设置项目.程序包的名称 设置项目名称为MyDiary,程序包名为org.socrates.mydiary.acti ...