Pagini recente » Cod sursa (job #875385) | Cod sursa (job #2140033) | Cod sursa (job #2135590) | Cod sursa (job #1974023) | Cod sursa (job #999935)
Cod sursa(job #999935)
#include <cstdio>
using namespace std;
const int Nmax = 100005;
int N,M,daddy[ Nmax ];
inline int whos_ur_daddy(int nodc)
{
if(daddy[nodc]!=nodc)
return whos_ur_daddy(daddy[nodc]);
return nodc;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&N,&M);
for(int i=1;i<=N;++i)daddy[i]=i;
int type,a,b;
while(M--)
{
scanf("%d%d%d",&type,&a,&b);
if(type == 1)
{
daddy[a]=whos_ur_daddy(a);
daddy[b]=whos_ur_daddy(b);
daddy[daddy[a]]=daddy[b];
}
else if( whos_ur_daddy(a)==whos_ur_daddy(b))
printf("DA\n");
else
printf("NU\n");
}
return 0;
}