Hdu2860regroup (and collection)

Source: Internet
Author: User

RegroupTime limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 660 Accepted Submission (s): 161


Problem Descriptionwhen ALPC42 got to a Panzer brigade, He is asked to build software to help them regroup the battalions or companies.
As the tradition of army, soldiers is rated according his or hers abilities, taking the rate as an integer. The fighting capacity of a company are determined by the soldier in this company whose rate is lowest. Now the recruits those rated is coming and joins the their companies to the order form HQ.
With the coming of new recruits, a big regroup action reached, asking to merge some companies into one. The designation of a company, however, 'll not being canceled, but remain for memorialize what's the company was done, means th E Designation of the company was still exist, but the company was gone, so it was unable to ask recruits to join this company , or merge the company into others.
A Strange thing is, the orders sometimes get wrong, send newbie to A company which are already merged into another, or mentioned some only-designation-existed companies. Such order could be rejected.
The Brigadier wants to know every change of all order, so the program should able to report the status of every order, TE Lling whether it is accept, and can query the fighting capacity of specified company. (To simplify,companies is numbered from 0 to n-1

InputThere may several test cases.
For each case, the integers in first line, N, K, M, telling that there is n companies, K soldiers already, and M orders n Eeds be executed. (1<=n, K, m<=100000).
Then K-lines with the integers r and C for each, telling a soldier with the rate R's now on company C
Then M. Lines followed, containing 3 kinds of orders, in upper case:
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) 
OutputFor each order, there is exact one, line to report, the result.
For AP and MG order, print "Accept" if it's able to being done, and execute it, or "Reject" if it's an illegal order.
For GT order, if company X was still exist (not merged to others), print as "Lowest rate:y." Which y is the minimal Of soldiers in this company. If there is no one in this company, tell "Company X is empty." If Company X is already merged to others, print "Company X was a part of company Z." Z are the company where the company X is in.
Print a blank line after each case

Sample Input
5 5 0GT 0GT 3AP 3 3GT 3GT 4MG 3 4GT 4MG 1 3GT 4GT 1

Sample Output
Lowest Rate:5.company 3 is empty. Acceptlowest Rate:3.company 4 is empty. Acceptcompany 4 are a part of the company 3.AcceptCompany 4 are a part of the company 1.Lowest Rate:3.
Look at the code to understand test instructions.
#include <stdio.h>const int N = 100005;int fath[n],val[n],n;void init () {for (int i=0;i<=n;i++) fath[i]=i , Val[i]=-1;}    int Findfath (int x) {if (x!=fath[x]) Fath[x]=findfath (fath[x]); return fath[x];}    int main () {int k,m,a,b;    Char st[20];        while (scanf ("%d%d%d", &n,&k,&m) >0) {init ();            while (k--) {scanf ("%d%d", &a,&b); if (val[b]==-1| |        Val[b]>a) Val[b]=a;            } while (m--) {scanf ("%s", ST);                if (st[0]== ' A ') {scanf ("%d%d", &a,&b); if (fath[b]==b) {if (val[b]==-1| |                    Val[b]>a) Val[b]=a;                printf ("accept\n");            } else printf ("reject\n");                } else if (st[0]== ' M ') {scanf ("%d%d", &a,&b); if (fath[a]!=a| | fath[b]!=b| |              A==B)  {printf ("reject\n"); continue;                } printf ("accept\n"); if (val[a]==-1| |                VAL[B]!=-1&AMP;&AMP;VAL[A]&GT;VAL[B]) val[a]=val[b];            Fath[b]=a;                } else {scanf ("%d", &a);                    if (fath[a]!=a) {B=findfath (a);                printf ("Company%d was a part of the company%d.\n", A, b); } else {if (val[a]==-1) printf ("Company%d is empt                    Y.\n ", a);                else printf ("Lowest Rate:%d.\n", Val[a]);    }}} printf ("\ n"); }}


Hdu2860regroup (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.