HDU 1434 Happy Train

Source: Internet
Author: User
Tags strcmp

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=1434

Happy Train description

A group of happy trains will sail from Hangzhou to the happy end-Wenzhou, Linle, a chief conductor, has some strange quirks.

He would record all the passenger's names (name) and their character values (RP), according to these sort them, and occasionally from a train to play the most bad character (RP value of the lowest) of a person, when two people are as bad as the character, he will kick out the name of the nasty person (Linle think in dictionary order, The more people who are in the back, the worse the name is.

Of course, because of the need for the train, he also occasionally issued a number of orders, such as getting a passenger to the car, merging a two train and so on.

Linle's last secretary was fired for not being able to execute his orders efficiently, he is now looking for a new secretary, can you do it? (No men, very generous ~ ~ ~)

Input

The subject contains multiple sets of tests, please handle to the end of the file.
For each set of tests, the first row contains two integers n, m, representing a total of n (n<=10000) trains, performing M (m<=10000) operations.
Next there is an N (counting from 1) train information, each train has a number XI (1 <= XI <= 100), indicating that the train has XI passengers, followed by Xi passenger information, each passenger contains the name (20 characters, not including the blank character) and character (0<= RP <=30000).
Then there is the M-line operation information, a total of 3 operations, respectively,

Geton XI name RP indicates that there is a character named name for the RP person aboard the first XI train

JOIN XI XJ represents the merger of the first XJ train to the Xi train

Getout Xi says a man of the worst character is kicked out of the first XI train

The test data ensures that each operation is legal, that the trains that have been merged into other trains are not merged, and that no passengers are kicked out of an empty train

Output

For each getout command, the output is kicked out of the name of the person who

Sample Input

3 5
2
XHD 0
ZL 1
2
8600 1
LL 2
1
Ignatius 3
Getout 1
JOIN 1 2
Getout 1
Geton 3 HoHo 2
Getout 3

Sample Output

Xhd
Zl
HoHo

Priority queue, when the queue is merged with the heap to be faster, eh. Too lazy to write.

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <string>8#include <queue>9#include <map>Ten usingstd::cin; One usingstd::cout; A usingStd::endl; - usingStd::find; - usingStd::sort; the usingStd::map; - usingstd::p air; - usingSTD::string; - usingstd::vector; + usingStd::multimap; - usingstd::p riority_queue; + #definePB (E) push_back (e) A #defineSZ (c) (int) (c). Size () at #defineMP (A, b) Make_pair (A, B) - #defineAll (c) (c). Begin (), (c). End () - #defineITER (c) Decltype ((c). Begin ()) - #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 0; i < (int) (n); i++) in #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - Const intN =10010; totypedef unsignedLong Longull; + structNode { -     intRP; the     stringname; *Node (inti =0,stringj =""): RP (i), name (j) {} $InlineBOOL operator< (ConstNode &a)Const {Panax Notoginseng         returnRP = = A.rp? Name < A.NAME:RP >A.RP; -     } the }; +Priority_queue<node>Que[n]; A intMain () { the #ifdef LOCAL +Freopen ("In.txt","R", stdin); -Freopen ("OUT.txt","w+", stdout); $ #endif $     Charbuf[ A],tmp[ A]; -     intN, M, RP, Xi, XJ; -      while(~SCANF ("%d%d", &n, &m)) { the          for(inti =1; I <= N; i++) { -scanf"%d", &xi);Wuyi              while(xi--) { thescanf"%s%d", BUF, &RP); - Que[i].push (Node (RP, buf)); Wu             } -         } About          while(m--) { $scanf"%s", buf); -             if(!STRCMP (BUF,"Geton")) { -scanf"%d%s%d", &AMP;XI, TMP, &RP); - Que[xi].push (Node (RP, TMP)); A}Else if(!STRCMP (BUF,"JOIN")) { +scanf"%d%d", &xi, &XJ); the                  while(!Que[xj].empty ()) { - Que[xi].push (Que[xj].top ()); $ Que[xj].pop (); the                 } the}Else { thescanf"%d", &xi); theprintf"%s\n", Que[xi].top (). NAME.C_STR ()); - Que[xi].pop (); in             } the         } theRep (i, n +1) while(!que[i].empty ()) Que[i].pop (); About     } the     return 0; the}
View Code

HDU 1434 Happy Train

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.