Pagini recente » Cod sursa (job #2680845) | Cod sursa (job #2914223) | Cod sursa (job #828993) | Cod sursa (job #1559900) | Cod sursa (job #2000639)
#include <cstdio>
using namespace std;
int t[100005], h[100005];
int FindSet(int x)
{
while(t[x] != x)
x = t[x];
return x;
}
void UnionSet(int x, int y)
{
if(h[x] == h[y])
h[x]++, t[y] = x;
else if(h[x] > h[y])
t[y]=x;
else
t[x]=y;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int N, M, o, i, x, y;
scanf("%d%d", &N, &M);
for(i=1 ; i<=N ; i++)
h[i]=1, t[i]=i;
for(i=1 ; i<=M ; i++)
{
scanf("%d%d%d", &o, &x, &y);
if(o == 1)
UnionSet(x,y);
else
if(FindSet(x) == FindSet(y))
printf("DA");
else
printf("NU");
}
return 0;
}