Pagini recente » Cod sursa (job #1826540) | Cod sursa (job #1512554) | Cod sursa (job #269077) | Cod sursa (job #2522846) | Cod sursa (job #3030630)
#include <fstream>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;
string file = "disjoint";
ifstream cin (file + ".in");
ofstream cout (file + ".out");
const int N = 100000;
int t[N+1];
int radacina (int x)
{
if (t[x] == 0)
{
return x;
}
t[x] = radacina(t[x]);
return t[x];
}
int main()
{
int n,m,op,x,y;
cin >> n >> m;
for (int i=1; i<=m; i++)
{
cin >> op >> x >> y;
if (op == 1)
{
if (x > y)
swap(x,y);
t[y] = x;
}
else
{
int rx = radacina(x);
int ry = radacina(y);
if (rx && ry && rx == ry)
{
cout << "DA\n";
}
else
{
cout << "NU\n";
}
}
}
}