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的关系,只要他 ...
随机推荐
- 一步一步学python(三) - 使用字符串
1.基本字符串操作 序列和元组的索引.分片.乘法.判断成员资格.求长度.取最小值和最大值对字符串同样适用. 字符串是不可变的 2.字符串格式化 %左侧放字符串右侧放格式化的值.一般情况下使用元组 fo ...
- https://pta.patest.cn/pta/test/15/exam/3/question/724
List Reverse( List L ){ if(L==NULL) return; List head=(List)malloc(sizeof(struct Node)); head->Ne ...
- User has no SELECT privilege on V$SESSION
今天是2013-09-20,最近心情一直很差,但是也不能不学习啊,无论怎么样,自己学到 的东西永远都是自己的.加油! 使用dbms_xplan.display_cursor function ...
- 打包静态库.a文件的方法(ar,ranlib,nm命令介绍)
一 常用脚本 1 打包脚本 脚本如下,下面附上ar 和 ranlib命令参考(命令来自于网络) ALLLIB=*.aFILE=`ls *.a`#原来的库解压重命名 for F in $FILEdo ...
- Java报错--Unsupported major.minor version 52.0
遇到一个Java相关的报错: ... java.lang.UnsupportedClassVersionError: ... : Unsupported major.minor version 52. ...
- DB2数据库常用基本操作命令
点击开始菜单-->所有程序-->IBM-->DB2-->DB2COPY1-->命令行工具-->命令窗口一.DB2实例操作1.查看DB2数据库的版本及安装目录 E:\ ...
- 【MFC学习笔记-作业8-蝴蝶飞~】【什么鬼作业】
作业要求: 用定时器控制蝴蝶在窗口废物,如图所示... 这是什么鬼作业啊...蝴蝶还要我这个手残手画啊233333333 (ノಠ .ಠ)ノ彡┻━┻ 不过多亏之前几个鬼作业的福 收获颇 ...
- lamda表达式学习
lamda表达式 “Lambda 表达式”是一个匿名函数,它可以包含表达式和语句,并且可用于创建委托或表达式目录树类型. 格式:( 形参列表 ) => { 函数体 } 所有 Lambda 表达式 ...
- asp.net中的绝对路径和相对路径
一.关于相对路径和绝对路径相对路径转绝对路径一般,我们在ASP.NET网站中往往需要把一个相对路径转化为绝对路径.通常是用Server.MapPath()方法.比如网站根目录下有 个"Upl ...
- Free Sql Server SMSS format Plugin
免费Sql Server 格式化插件 http://www.apexsql.com/sql_tools_refactor.aspx http://architectshack.com/PoorMans ...