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. jsp 2种include标签的区别

    众所周知,jsp中有2种标签用于包含其他jsp或者文件 1.include指令,其实是java代码 <%@ include file="xxx.jsp"%> 2.jsp ...

  2. UI组件

    1.自定义View 2.布局管理器-----ViewGroup 3.textview及其子类 4.imageview及其子类 5.adapterview及其子类----ViewGroup 6.prog ...

  3. Python中的图形库

    Python中的图形库 根据Python 2.x的官网文档的解释: Graphical User Interfaces with Tk 和 Other Graphical User Interface ...

  4. 判图的连通性(dfs,并查集)

    一.无向图 欧拉回路:每个顶点度数都是偶数 欧拉路:所有点度数为偶数,或者只有2个点度数为奇数 当然判连通性 hdu 1878 欧拉回路 两种判连通的方法 dfs #include <iostr ...

  5. hdu 5620 KK's Steel(推理)

    Problem Description Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters s ...

  6. hdu 5569 matrix(简单dp)

    Problem Description Given a matrix with n rows and m columns ( n+m ,) and you want to go to the numb ...

  7. bzoj 维护序列seq(双标记线段树)

    Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 4184  Solved: 1518[Submit][Status][Discus ...

  8. 只获取linux ip的命令

    ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'

  9. DSOframer 微软官方API的查阅方法

    不了解 DSOframer 的朋友,可以先参考文章 DSOframer 的简单介绍和资源整理. 大家在使用 DSOframer 时,常常会不知道在哪里查 API 文档,网上的文章都非常零散,很难找到自 ...

  10. js事件的相关收集

    1.阻止事件冒泡: IE:cancelBubble = true; 其他: stopPropagation(); 2.阻止事件的默认行为: IE: returnValue = false; 其他: p ...