Pagini recente » Cod sursa (job #2066918) | Cod sursa (job #754238) | Cod sursa (job #1930530) | Cod sursa (job #1501320) | 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;
}