Pagini recente » Cod sursa (job #1675130) | Cod sursa (job #2950228) | Cod sursa (job #638948) | Cod sursa (job #2950227) | Cod sursa (job #2951864)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, x, y, op;
int t[100005];
void unire(int x, int y)
{
t[y] = x;
}
int radacina(int x)
{
int aux;
int r = x;
while(t[r])
{
r = t[r];
}
while(t[x])
{
aux = t[x];
t[x] = r;
x = aux;
}
return r;
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i ++)
{
fin >> op >> x >> y;
x = radacina(x);
y = radacina(y);
if(op == 1)
{
unire(x, y);
}
if(op == 2)
{
if(x == y)
fout << "DA";
else
fout << "NU";
fout << "\n";
}
}
return 0;
}