Title Address: POJ 3723
Maximum Spanning Tree: Same as the minimum spanning tree principle. Just the order of the sort changed.
The code is as follows:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace STD;#define LL __int64#define PI ACOs ( -1.0)//#pragma comment (linker, "/stack:1024000000")Const intMod=1e9+7;Const intinf=0x3f3f3f3f;Const Doubleeqs=1e-9;Const intmaxn=40000+Ten;intbin[30000], CNT;structnode{intU, V, W;} edge[60000];voidAddintUintVintW) {edge[cnt].v=v; Edge[cnt].w=w; Edge[cnt++].u=u;}BOOLCMP (node f1, node F2) {returnF1.W>F2.W;}intFind1 (intx) {returnBin[x]==x?x:bin[x]=find1 (Bin[x]);}intKrus (intN) {intI, F1, F2; Sort (edge,edge+cnt,cmp);intans=0; for(i=0; i<cnt;i++) {f1=find1 (bin[edge[i].u]); F2=find1 (BIN[EDGE[I].V]);if(F1!=F2) {ANS+=EDGE[I].W; BIN[F2]=F1; } }returnAns;}voidInitintN) {cnt=0; for(intI=0; i<n;i++) {bin[i]=i; }}intMain () {intN, M, I, J, U, V, W, T, q, ans;scanf("%d", &t); while(t--) {scanf("%d%d%d", &n,&m,&q); Init (n+m); while(q--) {scanf("%d%d%d", &u,&v,&w); Add (U,V+N,W); }printf("%d\n", (m+n) *10000-krus (n+m)); }return 0;}
POJ 3723 Conscription (maximum spanning tree)