Pagini recente » Cod sursa (job #687507) | Cod sursa (job #2929985) | Cod sursa (job #2439280) | Cod sursa (job #2458521) | Cod sursa (job #2280038)
#include <bits/stdc++.h>
#define dm 100005
std :: ifstream fin("disjoint.in");
std :: ofstream fout("disjoint.out");
using namespace std;
int v[dm], n, m;
int root(int x)
{
if(v[x] == x)
return x;
else
return v[x] = root(v[x]);
}
void mash(int x, int y)
{
v[root(x)] = root(y);
}
struct operatii{
int type;
int x;
int y;
}query[dm];
int main()
{
fin >> n >> m;
for(int i = 1; i <= n; i++)
v[i] = i;
for(int i = 1; i <= m; i++)
fin >> query[i].type >> query[i].x >> query[i].y;
for(int i = 1; i <= m; i++)
{
if(query[i].type == 1)
mash(query[i].x, query[i].y);
else if(query[i].type == 2)
{
if(root(query[i].x) == root(query[i].y))
{
fout << "DA" << "\n";
}
else fout << "NU" << "\n";
}
}
return 0;
}