Pagini recente » Cod sursa (job #1800461) | Cod sursa (job #1703309) | Borderou de evaluare (job #224780) | Cod sursa (job #425172) | Cod sursa (job #3039575)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
string filename = "mergeheap";
#ifdef LOCAL
ifstream fin("input.in");
ofstream fout("output.out");
#else
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
#endif
const int NMAX = 100;
priority_queue <int> pq[NMAX + 1];
signed main(){
int n, q;
fin >> n >> q;
while(q--){
int t;
fin >> t;
if(t == 1){
int m, x;
fin >> m >> x;
pq[m].push(x);
}else if(t == 2){
int m;
fin >> m;
fout << pq[m].top() << '\n';
pq[m].pop();
}else{
int a, b;
fin >> a >> b;
swap(a, b);
if((int)pq[a].size() > (int)pq[b].size()){
pq[a].swap(pq[b]);
}
while(!pq[a].empty()){
pq[b].push(pq[a].top());
pq[a].pop();
}
}
}
return 0;
}