Pagini recente » Cod sursa (job #2211744) | Cod sursa (job #2922376) | Cod sursa (job #412419) | Cod sursa (job #2403114) | Cod sursa (job #1581744)
#include <cstdio>
#define NMax 100005
using namespace std;
int root[NMax];
int x,y,n,m,p;
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1; i <= m; ++i){
scanf("%d%d%d",&p,&x,&y);
if(p == 1){
root[y] = x;
}else{
int w = y;
while(root[w] != 0)
w = root[w];
int t = x;
while(root[t] != 0)
t = root[t];
if(t != w){
printf("NU\n");
}else
printf("DA\n");
}
}
return 0;
}