Cod sursa(job #2750629)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 12 mai 2021 17:08:40
Problema Heapuri cu reuniune Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;

const string filename = "mergeheap";

ifstream fin(filename + ".in");
ofstream fout(filename + ".out");


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

int n, t;

int main()
{
	short op;
	int x, y;
	fin >> n >> t;
	vector< __gnu_pbds::priority_queue<int, less<int>, pairing_heap_tag> > q(n + 1);

	while (t--)
	{
		fin >> op;
		if (op == 1)
		{
			fin >> x >> y;
			q[x].push(y);
		}
		else if (op == 2)
		{
			fin >> x;
			fout << q[x].top() << '\n';
			q[x].pop();
		}
		else
		{
			fin >> x >> y;
			q[x].join(q[y]);
		}
	}

	fin.close();
	fout.close();
	return 0;
}