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的关系,只要他 ...
随机推荐
- Delphi通过GetFileVersionInfo和VerQueryValue等API函数取得详细EXE信息
This has been described at About: http://delphi.about.com/cs/adptips2001/a/bltip0701_4.htmBasically, ...
- inno setup 跳过(Welcome)欢迎界面
原文 http://zwkufo.blog.163.com/blog/static/25882512010816049549/ 在InnoSetup中,我们很容易用 function ShouldSk ...
- windows窗口分析,父窗口,子窗口,所有者窗口
(本文尝试通过一些简单的实验,来分析Windows的窗口机制,并对微软的设计理由进行一定的猜测,需要读者具备C++.Windows编程及MFC经验,还得有一定动手能力.文中可能出现一些术语不统一的现象 ...
- (译)"usermod"命令使用完全指导---15个练习例程截图
"usermod"命令使用完全指导---15个练习例程截图 By Babin Lonston Under: Linux Commands On: November 11, 2014 ...
- #include <boost/shared_ptr.hpp>
共享指针 这个智能指针命名为boost::shared_ptr,定义在boost/shared_ptr.hpp里.智能指针boost::shared_ptr基本上类似于boost::scoped_pt ...
- 吐槽下CSDN编辑器
Perface 近期喜欢上了markdown,我认为它就是一些HTML标签的快捷键,用一些符号来取代标签,易学易读易用,何乐而不为呢?近期也喜欢用印象笔记来让我的记忆永存,确实它强大的收集能力让我迷上 ...
- (原)工具篇-利用fis压缩项目
fis3 1.添加 fis-conf.js 到项目根目录中 fis-conf.js 内容如下 : //配置MD5版本控制 fis.match('*.{js,css,png,jpg}', { useHa ...
- 一点用JS写控制权限的心得
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Gabor滤波器学习
本文的目的是用C实现生成Gabor模版,并对图像卷积.并简单提一下,Gabor滤波器在纹理特征提取上的应用. 一.什么是Gabor函数(以下内容含部分翻译自维基百科) 在图像处理中,Gabor函数是一 ...
- 疯狂Java讲义 第一章控制台五子棋(代码分析)
package com.test; public class Chessboard { //定义二维数组作为棋盘 private String[][] board; //定义棋盘大小 public s ...