Pagini recente » Cod sursa (job #734635) | Cod sursa (job #2067665) | Cod sursa (job #539522) | Cod sursa (job #698452) | Cod sursa (job #2249515)
#include <fstream>
#include <iostream>
#include <map>
#include <set>
using namespace std;
ifstream in { "disjoint.in" };
ofstream out { "disjoint.out" };
void uneste(map<int, set<int>>& p, int x, int y) {
if (x > y)
swap(x, y);
for (auto& i : p[y])
p[x].insert(i);
p[x].insert(y);
p[y].clear();
}
void verifica(map<int, set<int>>& p, int x, int y) {
if (x > y)
swap(x, y);
out << (p[x].find(y) != p[x].end() ? "DA\n" : "NU\n");
}
int main() {
int n, m;
in >> n >> m;
map<int, set<int>> p;
while (m--) {
int c, x, y;
in >> c >> x >> y;
if (c == 1)
uneste(p, x, y);
else
verifica(p, x, y);
}
}