Cod sursa(job #2906178)
Utilizator | Iordache Ana-Georgiana Iordache_Ana | Data | 25 mai 2022 00:21:18 |
---|---|---|---|
Problema | Heapuri cu reuniune | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.79 kb |
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream f("mergeheap.in");
ofstream g("mergeheap.out");
int main()
{
priority_queue<int> h[102];
int N,Q,operatie,a,b;
f>>N>>Q;
for(int i=0; i<Q; ++i)
{
f>>operatie;
if(operatie==1)
{
f>>a>>b;
h[a].push(b);
}
else if(operatie==2)
{
f>>a;
g<<h[a].top()<<'\n';
h[a].pop();
}
else
{
f>>a>>b;
if(h[b].size()>h[a].size())
swap(h[a],h[b]);
while(!h[b].empty())
{
h[a].push(h[b].top());
h[b].pop();
}
}
}
return 0;
}