UVA540 RE on #1
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <bits/stdc++.h>
#include <stack>
using namespace std;
struct team{
int a[10010];
int n;
};
struct teamqueue{
queue <int> t;
};
int main(){
int n;
int sc = 1;
while(cin >> n){
if(n == 0) break;
const int N = n+10;
team a[N];
int tong[1000010];
for(int i = 1;i <= n;i++){
cin >> a[i].n;
for(int j = 1;j <= a[i].n;j++){
cin >> a[i].a[j];
tong[a[i].a[j]] = i;
}
}
queue <int> t;
bool flag[10010];
for(int i = 1;i <= n;i++) flag[i] = false;
teamqueue q[10010];
string s;
cout << "Scenario #" << sc << endl;
while(cin >> s){
if(s == "STOP"){
break;
}else if(s == "ENQUEUE"){
int x;
cin >> x;
if(flag[tong[x]] == false){
flag[tong[x]] = true;
t.push(tong[x]);
//cout << "tp" << endl;
}
q[tong[x]].t.push(x);
}
if(s == "DEQUEUE"){
// cout << t.empty() << endl;
cout << q[t.front()].t.front() << endl;
q[t.front()].t.pop();
if(q[t.front()].t.empty()){
t.pop();
}
}
}
sc++;
cout << endl;
}
cout << endl;
return 0;
}