Pagini recente » Cod sursa (job #1677775) | Cod sursa (job #659027) | Cod sursa (job #960677) | Cod sursa (job #3259021) | Cod sursa (job #499120)
Cod sursa(job #499120)
#include <stdio.h>
#define Nmax 100001
int N, M, T[Nmax];
int get_root(int x) {
while(T[x]!=x)
x=T[x];
return x;
}
int main() {
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int i, tip, x, y, root1, root2;
scanf("%d %d",&N,&M);
for (i=1; i<=N; i++)
T[i]=i;
while(M--) {
scanf("%d %d %d",&tip,&x,&y);
root1=get_root(x); root2=get_root(y);
if(tip==1) {
if(root1<root2)
T[root2]=root1;
else
T[root1]=root2;
}
else
printf("%s\n", root1==root2 ? "DA" : "NU");
}
return 0;
}