Pagini recente » Cod sursa (job #986727) | Cod sursa (job #2350250) | Cod sursa (job #1472112) | Cod sursa (job #2647600) | Cod sursa (job #2645258)
#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;
}