Pagini recente » Cod sursa (job #3129240) | Cod sursa (job #1354159) | Cod sursa (job #1789593) | Cod sursa (job #770420) | Cod sursa (job #418420)
Cod sursa(job #418420)
#include <cstdio>
#define IN "disjoint.in"
#define OUT "disjoint.out"
#define NMAX 100100
int N, M;
int TT[NMAX];
int find(int x)
{
int r, aux;
for(r = x ; TT[r] != r ; r = TT[r]);
while(TT[x] != x)
{
x = TT[x];
TT[x] = r;
}
return r;
}
int main()
{
int ide, x, y;
freopen(IN,"r",stdin);
freopen(OUT,"w",stdout);
scanf("%d%d",&N,&M);
for(int i = 1 ; i <= N ; i++)
TT[i] = i;
for(int i = 1 ; i <= M ; i++)
{
scanf("%d%d%d",&ide,&x,&y);
if(ide == 1)
TT[find(x)] = find(y);
else
{
if(find(x) == find(y))
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}