Pagini recente » Borderou de evaluare (job #2463841) | Cod sursa (job #3039778)
/// Preset de infoarena
#include <fstream>
#include <iostream>
#include <queue>
using namespace std;
ifstream fin("mergeheap.in");
ofstream fout("mergeheap.out");
const int maxN = 105;
int n, q;
priority_queue <int> heap[maxN];
int main()
{
fin >> n >> q;
while(q--)
{
int op;
fin >> op;
if(op == 1)
{
int m, x;
fin >> m >> x;
heap[m].push(x);
}
if(op == 2)
{
int m;
fin >> m;
fout << heap[m].top() << '\n';
heap[m].pop();
}
if(op == 3)
{
int m1, m2;
fin >> m1 >> m2;
if(heap[m1].size() < heap[m2].size())
heap[m1].swap(heap[m2]);
while(!heap[m2].empty())
{
int x = heap[m2].top();
heap[m2].pop();
heap[m1].push(x);
}
}
}
return 0;
}