Pagini recente » Cod sursa (job #953565) | Cod sursa (job #2661492) | Cod sursa (job #3194145) | Clasament captainbobulous | Cod sursa (job #1340868)
#include <cstdio>
#define nmax 100000
using namespace std;
int n,m;
int t[nmax];
int getA(int x)
{
while (t[x] != x) x = t[x];
return x;
}
void set(int t2,int b)
{
while (t[b] != b)
{
int pastB = b;
b = t[b];
t[pastB] = t2;
}
t[b] = t2;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d %d",&n,&m);
for (int i=1;i<=n;i++) t[i] = i;
for (int qi=1;qi<=m;qi++)
{
int type,a,b;
scanf("%d %d %d",&type,&a,&b);
if (type == 1)
{
int t1 = getA(a);
set(t1,b);
}
else
{
int t1 = getA(a);
int t2 = getA(b);
if (t1 == t2)
{
printf("DA\n");
}
else
{
printf("NU\n");
}
}
}
}