#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string.h> #include<queue> #include<vector> #define maxint 999999999 #define MAXN 10005 #define ll long long using namespace std; int n,m,k,flag,num; ll sum; int Mark[MAXN],st[MAXN],vis[MAXN]; struct Q{ char name[25]; int val; }; bool operator <(const Q &x,const Q &y){ int Min=min(strlen(x.name),strlen(y.name)); if(x.val!=y.val) return x.val>y.val; for(int i=0;i<Min;i++){ if(x.name[i]!=y.name[i]) return x.name[i]<y.name[i]; } } int main() { int l,a,b,c,d; char str[20]; while(scanf("%d %d",&n,&m)!=EOF){ Q z; priority_queue<Q>q[MAXN]; for(int i=1;i<=n;i++){ scanf("%d",&l); for(int j=1;j<=l;j++){ scanf("%s %d",z.name,&z.val); q[i].push(z); } } for(int i=1;i<=m;i++){ scanf("%s",str); if(strlen(str)==4){ scanf("%d %d",&a,&b); while(!q[b].empty()){ q[a].push(q[b].top()); q[b].pop(); } } else if(strlen(str)==6){ scanf("%d",&c); printf("%s\n",q[c].top().name); q[c].pop(); } else if(strlen(str)==5){ Q w; scanf("%d",&d); scanf("%s %d",w.name,&w.val); q[d].push(w); } } for(int i=1;i<n;i++){ while(!q[i].empty()){ q[i].pop(); } } }return 0; }
时间: 2024-11-10 04:12:06