Pagini recente » Cod sursa (job #2502774) | Borderou de evaluare (job #1794310) | Cod sursa (job #3264973) | Cod sursa (job #15055) | Cod sursa (job #1394399)
#include <iostream>
#include<fstream>
#include<cstdio>
using namespace std;
int n,m,i,t[100001],x,y,cod,tx,ty;
int findt(int x)
{
if(x!=t[x])
return t[x]=findt(t[x]);
else return x;
}
void unite(int x,int y)
{
tx=findt(x);
ty=findt(y);
t[tx]=ty;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n, &m);
for(i=1;i<=n;i++)
t[i]=i;
for(i=1;i<=m;i++)
{
scanf("%d%d%d", &cod, &x, &y);
if(cod==1) unite(x,y);
else if(findt(x)==findt(y)) printf("DA\n");
else printf("NU\n");
}
return 0;
}