| 4021 Conscription Plan |
| Difficulty level: C; programming language: Unlimited; run time limit: 1000ms; run space limit: 51200KB; code length limit: 2000000B |
| Question Description |
It is now necessary to recruit a female soldier N, a male soldier m, and each recruit will cost $10000, but if some of the people who have been recruited have close relationships, they can spend less money. Given the value of a number of intimate relationships between men and women (expressed in 1 to 9999), the cost of recruiting a person is 10000 minus the maximum value of intimacy with the person recruited. The need for the recruitment of all persons is minimized through appropriate recruitment sequence arrangements. |
| Input |
| The first line consists of three numbers n,m and R, followed by the R line, each line consists of three numbers x, Y, and D, which indicates that the intimacy between the X-Men and the female soldier y is D, and the number of rows is separated by a vacancies of 22. |
| Output |
| A number that represents the cost of conscription. |
| Input example |
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 |
| Output example |
| 71071 |
| Other Notes |
| Data range: 1<=n,m<=10000,0<=r<=50000,0<d<10000,0<=x<m,0<=y<n. |
Problem: It's too much of a hole ... Men and women formed a natural binary map, on a variety of yy binary map matching god horse's ... Can't do it ...
Finally carefully painted a, mom Ah, this is not a bare build tree it ..........
Crying blind ...
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=50000+Ten; One structnode{ A int from, To,c; - BOOL operator< (ConstNode&a)Const{returnc<A.C;} -}A[MAXN];intN,M,K,P[MAXN]; the intFindintx) {returnp[x]==x?x:p[x]=find (P[x]);} -InlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; + for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; - returnsig?x:-x; + } AInlinevoidWriteintx) { at if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; - for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } - voidinit () { -N=read (); M=read (); k=read (); in for(intI=0; i<=n+m;i++) p[i]=i; - for(intI=0; i<k;i++){ to intU=read (), V=read (), c=read (); +A[i]= (node) {u,v+n,10000-C}; - } theSort (a,a+k);intcn1=0, cnt=0; * for(intI=0; i<k;i++){ $ intX=find (A[i]. from), y=find (a[i].to);Panax Notoginseng if(x!=y) p[x]=y,ans+=a[i].c,cnt++; - } theans+= (n+m-cnt) *10000; + write (ans); A return; the } + voidWork () { - return; $ } $ voidprint () { - return; - } the intMain () {init (); work ();p rint ();return 0;}
Coj 0580 4021 Conscription plan