Cod sursa(job #3041395)
Utilizator | Voica Stefan stefanvoica | Data | 31 martie 2023 13:49:17 |
---|---|---|---|
Problema | Heapuri cu reuniune | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.78 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin ("mergeheap.in");
ofstream fout("mergeheap.out");
int n,m;
priority_queue<int>pq[102];
int main ()
{
int op,x,y;
fin>>x>>m;
while (m--)
{
fin>>op>>x;
if (op==2)
{
fout<<pq[x].top()<<'\n';
pq[x].pop();
}
else
{
fin>>y;
if (op==1)
pq[x].push(y);
else ///le torn in x
{
if (pq[x].size() < pq[y].size())
swap(pq[x],pq[y]);
while (!pq[y].empty())
{
pq[x].push(pq[y].top());
pq[y].pop();
}
}
}
}
}