Cod sursa(job #2645258)

Utilizator ZahaZaharie Stefan Zaha Data 27 august 2020 16:35:00
Problema Paduri de multimi disjuncte Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
#include <set>
using namespace std;

ifstream fin("disjoint.in");
ofstream fout("disjoint.out");

set<int> neighbours[100005];

int main() {
    int n, m;
    fin >> n >> m;

    for (int i = 1; i <= m; ++i) {
        int type, x, y;
        fin >> type >> x >> y;

        if (type == 1) {
            for (int i : neighbours[x])
                neighbours[y].emplace(i);
            for (int i : neighbours[y])
                neighbours[x].emplace(i);

            neighbours[x].emplace(y);
            neighbours[y].emplace(x);
        }
        else {
            auto found = neighbours[x].find(y);

            if (found != neighbours[x].end())
                fout << "DA\n";
            else
                fout << "NU\n";
        }
    }

    return 0;
}