fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const char el = '\n';
  4. using ll = long long;
  5.  
  6. int teamOf[1000000];
  7.  
  8. int main() {
  9. cin.tie(0)->sync_with_stdio(0);
  10.  
  11. int t;
  12. int scenario = 1;
  13. while (cin >> t && t != 0) {
  14. for (int i = 0; i < t; i++) {
  15. int n;
  16. cin >> n;
  17. for (int j = 0; j < n; j++) {
  18. int x;
  19. cin >> x;
  20. teamOf[x] = i;
  21. }
  22. }
  23. queue<int> teamQ;
  24. queue<int> q[1000];
  25. bool inQ[1000] = {};
  26. cout << "Scenario #" << scenario++ << el;
  27. string c;
  28. while (cin >> c && c != "STOP") {
  29. if (c == "ENQUEUE") {
  30. int x;
  31. cin >> x;
  32. int team = teamOf[x];
  33. if (!inQ[team]) {
  34. teamQ.push(team);
  35. inQ[team] = true;
  36. }
  37. q[team].push(x);
  38. }
  39. else if (c == "DEQUEUE") {
  40. int team = teamQ.front();
  41. cout << q[team].front() << el;
  42. q[team].pop();
  43. if (q[team].empty()) {
  44. teamQ.pop();
  45. inQ[team] = false;
  46. }
  47. }
  48. }
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty