Cod sursa(job #2906156)

Utilizator Iordache_AnaIordache Ana-Georgiana Iordache_Ana Data 24 mai 2022 23:54:54
Problema Heapuri cu reuniune Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 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;
        switch(operatie)
        {


        case 1:
        {

            f>>a>>b;
            h[a].push(b);
            break;
        }
        case 2:
        {
            f>>a;
            g<<h[a].top()<<"\n";
            h[a].pop();
            break;
        }
        case 3:
        {
            f>>a>>b;
            while(!h[b].empty())
            {
                h[a].push(h[b].top());
                h[b].pop();
            }
        }
        }
    }
    return 0;
}