Pagini recente » Cod sursa (job #1302545) | Cod sursa (job #2258559) | Cod sursa (job #1658839) | Cod sursa (job #2480595) | Cod sursa (job #999930)
Cod sursa(job #999930)
#include <cstdio>
#include <vector>
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] = daddy[a];
}
else if( whos_ur_daddy(a)==whos_ur_daddy(b))
printf("DA\n");
else printf("NU\n");
}
return 0;
}