Pagini recente » Cod sursa (job #2838102) | Cod sursa (job #2367016) | Cod sursa (job #2524073) | Cod sursa (job #1090613) | Cod sursa (job #2906164)
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream f("mergeheap.in");
ofstream g("mergeheap.out");
int main()
{
priority_queue<int> h[105];
int N,Q,operatie,a,b,i;
f>>N>>Q;
for(i=1; i<=Q; ++i)
{
f>>operatie;
switch(operatie)
{
case 1:
{
f>>a>>b;
h[a].push(b);
break;
}
case 2:
{
f>>a;
g<<h[a].top()<<endl;
h[a].pop();
break;
}
case 3:
{
f>>a>>b;
if(h[a].size()>h[b].size())
swap(h[b],h[a]);
while(!h[b].empty())
{
h[a].push(h[b].top());
h[b].pop();
}
}
}
}
return 0;
}