HDU 4424 Conquer a New region and collection

Source: Internet
Author: User

Test instructions: Given the n points and n-1 edges, the maximum load of a to B is the minimum of the carrying capacity between A and B. At the center of a certain point, the maximum value of the sum of the carrying capacity is obtained.

Because the load between A and B is the minimum of the carrying capacity between them, the number of loads between two points is first sorted from large to small. Each time a merge has a A, a, b two sets, the amount of load between them (cost) is the current minimum, if B is merged to a, then the total carrying capacity of a is the total carrying capacity of a before a and A/b, the number of the median of the clothing set, namely Cost[a]=cost[a]+num[b]*cost.

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespaceStd;typedefLong Longll;Const intinf=1000000000;Const intmaxn=200005;intF[maxn];ll NUM[MAXN],COST[MAXN];structbranch{intA; intb; ll cost;} BRA[MAXN];BOOLCMP (Branch a,branch b) {returnA.cost>B.cost;}intFind (intx) {    if(x!=f[x]) f[x]=Find (f[x]); returnf[x];} ll Function (intN) {     for(intI=0; i<n-1; i++)    {        intA=Find (BRA[I].A); intb=Find (BRA[I].B); if(cost[a]+num[b]*bra[i].cost>=cost[b]+num[a]*bra[i].cost) {F[b]=A; Cost[a]+=num[b]*Bra[i].cost; Num[a]+=Num[b]; }        Else{F[a]=b; COST[B]+=num[a]*Bra[i].cost; NUM[B]+=Num[a]; }    }    returnCost[find (1)];}intMain () {//freopen ("In.txt", "R", stdin);    intN;  while(SCANF ("%d", &n)! =EOF) {         for(intI=0; i<=n;i++) {F[i]=i; Num[i]=1; } memset (Cost,0,sizeof(cost));  for(intI=0; i<n-1; i++) scanf ("%d%d%i64d",&bra[i].a,&bra[i].b,&bra[i].cost); Sort (Bra,bra+n-1, CMP); printf ("%i64d\n", Function (n)); }    return 0;}

HDU 4424 Conquer a New region and collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.