HDU 2860 Regroup (and collection)

Source: Internet
Author: User

Test instructions

AP x y
A recruit with ability rate X were asked to join Company Y. (0<=x<2^31, 0<=y<n)

MG x y
Company X and Company Y are merged. The new company is numbered as X. (0<=x, Y<n)

GT x
Report the fighting capacity of Company X. (0<=X<N)

Ideas:

And check the set, judge the various possible situations.

Code:

intn,k,m;intfa[100005], ability[100005];intFINDFA (intx) {    if(fa[x]==x)returnFa[x]; intt=Fa[x]; FA[X]=Findfa (fa[x]); ABILITY[X]=min (ability[x],ability[t]); returnfa[x];}intMain () { while(SCANF ("%d%d%d", &n,&k,&m)! =EOF) {Rep (i,0, N-1) {Fa[i]=i; Ability[i]=inf; } Rep (I,1, K) {            intrate,belongto; scanf ("%d%d",&rate,&belongto); ABILITY[BELONGTO]=min (ability[belongto],rate); }         while(m--){            Charope[5]; scanf ("%s", ope); if(ope[0]=='A'){                intx, y; scanf ("%d%d",&x,&y); intfatemp=Findfa (y); if(y!=fatemp) {Puts ("Reject"); }Else{Ability[fatemp]=min (ability[fatemp],x); Puts ("Accept"); }            }            Else if(ope[0]=='M'){                intx, y; scanf ("%d%d",&x,&y); intfx=FINDFA (x); intfy=Findfa (y); if(fx!=x | | fy!=y | | fx==FY) {Puts ("Reject"); }Else{ABILITY[FX]=min (ability[fx],ability[fy]); FA[FY]=FX; Puts ("Accept"); }            }            Else{                intx; scanf ("%d",&x); intfx=FINDFA (x); if(x!=FX) {printf ("Company %d was a part of the company%d.\n", X,FX); }                Else{                    if(ability[x]==inf) {printf ("Company %d is empty.\n", x); }Else{printf ("Lowest Rate:%d.\n", ability[x]); } }}} puts (""); }    return 0;}

HDU 2860 Regroup (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.