Pagini recente » Cod sursa (job #1016943) | Cod sursa (job #742640)
Cod sursa(job #742640)
#define MAX 100001
#include <stdio.h>
int T[MAX];
int tata(int nod){
if ( nod != T[nod]) T[nod] = tata(T[nod]);
return T[nod];
}
int main(){
int M, N, x, y, i, cod;
freopen("disjoint.in", "r", stdin);
scanf("%d%d", &N, &M);
freopen("disjoint.out", "w", stdout);
for (i = 1; i <= N; i++) T[i] = i;
for (i = 1; i <= M; i++){
scanf("%d%d%d", &cod, &x, &y);
x = tata(x);
y = tata(y);
if (cod == 1) T[x] = y;
else x == y ? printf("DA\n") : printf("NU\n");
}
return 0;
}