Pagini recente » Cod sursa (job #2260350) | Cod sursa (job #2596114) | Cod sursa (job #1146603) | Cod sursa (job #810621) | Cod sursa (job #625029)
Cod sursa(job #625029)
#include <iostream>
#include <cstdio>
#define NMax 100005
using namespace std;
int N, Father[NMax];
int Find (int X)
{
int Root=X;
for (; Father[Root]!=0; Root=Father[Root]);
while (Father[X]!=0)
{
int Y=Father[X];
Father[X]=Root;
X=Y;
}
return Root;
}
void Unite (int X, int Y)
{
Father[Find (Y)]=Find (X);
}
int main()
{
freopen ("disjoint.in", "r", stdin);
freopen ("disjoint.out", "w", stdout);
int NQ;
scanf ("%d %d", &N, &NQ);
for (; NQ>0; --NQ)
{
int Type, X, Y;
scanf ("%d %d %d", &Type, &X, &Y);
if (Type==1)
{
Unite (X, Y);
}
else
{
if (Find (X)==Find (Y))
{
printf ("DA\n");
}
else
{
printf ("NU\n");
}
}
}
return 0;
}