Conscription
Conscription
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 6
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.
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
#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的更多相关文章
- POJ 3723 Conscription 最小生成树
题目链接: 题目 Conscription Time Limit: 1000MS Memory Limit: 65536K 问题描述 Windy has a country, and he wants ...
- POJ 3723 Conscription
Conscription Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6325 Accepted: 2184 Desc ...
- Conscription poj3723(最大生成树)
Conscription Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6870 Accepted: 2361 Desc ...
- POJ 3723 Conscription (Kruskal并查集求最小生成树)
Conscription Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14661 Accepted: 5102 Des ...
- POJ3723 Conscription 【并检查集合】
Conscription Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8071 Accepted: 2810 Desc ...
- 【POJ - 3723 】Conscription(最小生成树)
Conscription Descriptions 需要征募女兵N人,男兵M人. 每招募一个人需要花费10000美元. 如果已经招募的人中有一些关系亲密的人,那么可以少花一些钱. 给出若干男女之前的1 ...
- Conscription(POJ 3723)
原题如下: Conscription Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16584 Accepted: 57 ...
- MST:Conscription(POJ 3723)
男女搭配,干活不累 题目大意:需要招募女兵和男兵,每一个人都的需要花费1W元的招募费用,但是如果有一些人之间有亲密的关系,那么就会减少一定的价钱,如果给出1~9999的人之间的亲密关系,现在要你求 ...
- poj - 3723 Conscription(最大权森林)
http://poj.org/problem?id=3723 windy需要挑选N各女孩,和M各男孩作为士兵,但是雇佣每个人都需要支付10000元的费用,如果男孩x和女孩y存在亲密度为d的关系,只要他 ...
随机推荐
- emacs使用指南
上大学的时候使用过几个简单的命令,用上windows后除了dos很少用命令行处理问题.现在MBP在手不用用emacs多可惜啊. 我上午搜索了下资料,都说emacs是神器,但是神不神看个人啦.这东西也不 ...
- mysql perl 抓取update语句
<pre name="code" class="html"><pre name="code" class="ht ...
- myeclipse 2013 git
1. 2.添加site http://download.eclipse.org/egit/updates-2.3 3.安装 完成后,查看windows->preference的team下面有gi ...
- HDU 1852 Beijing 2008 数论
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1852 这道题和HDU1452类似. 题意:给你一个n.k,让你求2008^n所有因子的和(包括1和本 ...
- nyoj 1238 最少换乘(dijkstra)
描述 欧洲某城是一个著名的旅游胜地,每年都有成千上万的人前来观光旅行.Dr. Kong决定利用暑假好好游览一番.. 年轻人旅游不怕辛苦,不怕劳累,只要费用低就行.但Dr. Kong年过半百,他希望乘坐 ...
- 11.2.0.3.7 PSU补丁升级
说明:这是新上线主机,还没有建库的.如果库已经存在,那么最后还要进行刷库操作呢! 环境:SUSE Linux Enterprise Server 11 sp1 (x86_64) 要求将数据库从11.2 ...
- 简易实现 TextView单行文本水平触摸滑动效果
为了方便查看,已使用markdown编辑形成新博文. 本文Mardown地址 近期做应用的时候实用到TextView单行长文本,当文本内容过长时候又想实现触摸水平滑动效果. 网上找了非常多,都没有看到 ...
- Android OpenCV实现图片叠加,水印
关于如何用纯OpenCV实现图片叠加的例子实在是太少,太多的是使用 C++,JNI实现的,如果要用C++的话,我们为啥不转行做C++ 下面的例子基于 Android JavaCV 实现了在im_bea ...
- Mysql Binlog Dump原理
Register 首先,我们需要伪造一个slave,向master注册,这样master才会发送binlog event.注册很简单,就是向master发送COM_REGISTER_SLAVE命令,带 ...
- 在Activity中动态设置TextView的隐藏属性
if (true) { //显示 viewHolder.tvLine.setVisibility(View.INVISIBLE);} else { //不显示 viewHolder.tvLine.se ...