Pagini recente » Cod sursa (job #1279443) | Cod sursa (job #1763705) | Cod sursa (job #647659) | Cod sursa (job #3274553) | Cod sursa (job #3030632)
#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;
int rx = radacina(x);
int ry = radacina(y);
if (op == 1)
{
if (x > y)
swap(x,y);
t[ry] = rx;
}
else
{
if (rx == ry)
{
cout << "DA\n";
}
else
{
cout << "NU\n";
}
}
}
}