Pagini recente » Cod sursa (job #2662770) | Cod sursa (job #618009) | Cod sursa (job #611384) | Cod sursa (job #2096013) | Cod sursa (job #2645264)
#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) {
set<int> toMove;
for (int i : neighbours[x])
toMove.emplace(i);
for (int i : neighbours[y])
toMove.emplace(i);
toMove.emplace(y);
toMove.emplace(x);
auto it1 = toMove.begin();
while (it1 != toMove.end()) {
auto it2 = it1;
++it2;
while (it2 != toMove.end()) {
neighbours[*it1].emplace(*it2);
neighbours[*it2].emplace(*it1);
++it2;
}
++it1;
}
}
else {
auto found = neighbours[x].find(y);
if (found != neighbours[x].end())
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}