Cod sursa(job #2906149)

Utilizator Iordache_AnaIordache Ana-Georgiana Iordache_Ana Data 24 mai 2022 23:50:24
Problema Heapuri cu reuniune Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream f("mergeheap.in");
ofstream g("mergeheap.out");
priority_queue <int> h[105];
int N,Q,operatie,a,b,i;
int main()
{
    f>>N>>Q;
    for(i=1; i<=Q; ++i)
    {
        f>>operatie;
        if(operatie==1)
        {
            f>>a>>b;
            h[a].push(b);
            break;
        }
        if(operatie==2)
        {
            f>>a;
            g<<h[a].top()<<"\n";
            h[a].pop();
            break;
        }
         if(operatie==3)
        {
            f>>a>>b;
            while(!h[b].empty())
            {
                h[a].push(h[b].top());
                h[b].pop();
            }
        }
    }
    return 0;
}