Pagini recente » Cod sursa (job #665781) | Cod sursa (job #1487457) | Cod sursa (job #932173) | Cod sursa (job #2970199) | Cod sursa (job #902608)
Cod sursa(job #902608)
#include<cstdio>
#include<vector>
#define N 100002
using namespace std;
int n;
int father[N];
int getfather(int node)
{
if(father[node]) return getfather(father[node]);
return node;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int m,type,x,y;
scanf("%d%d",&n,&m);
while(m--)
{
scanf("%d%d%d",&type,&x,&y);
if(type==1) father[getfather(x)]=getfather(y);
else if(getfather(x)==getfather(y)) printf("DA\n");
else printf("NU\n");
}
return 0;
}