Pagini recente » Cod sursa (job #2853732) | Cod sursa (job #1186285) | Cod sursa (job #3283225) | Cod sursa (job #1953418) | Cod sursa (job #1837202)
#include <cstdio>
#define MAX_N 100000
using namespace std;
int t[MAX_N+5];
int father(int x){
if (t[x]==x)
return x;
return t[x]=father(t[x]);
}
void join(int x, int y){
int rx=father(x), ry=father(y);
t[rx]=ry;
}
int main(){
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int n, m, i, cod, x, y;
scanf("%d%d", &n, &m);
for (i=1; i<=n; i++)
t[i]=i;
while (m--){
scanf("%d%d%d", &cod, &x, &y);
if (cod==1)
join(x, y);
else
if (father(x)==father(y))
printf("DA\n");
else printf("NU\n");
}
return 0;
}