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)