Cod sursa(job #2749221)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 5 mai 2021 22:12:01
Problema Heapuri cu reuniune Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.14 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define imax INT_MAX
#define llmax LLONG_MAX
#define sz(x) (int((x).size()))
#define start ios_base::sync_with_stdio(false), cin.tie(0)
#define finish fin.close(), fout.close()


using ll = long long;
using uint = unsigned int;

const string filename = "file";

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

int n, t;

int main()
{
	start;

    int op, 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]);
        }

    }

	finish;
	return 0;
}