Pagini recente » Istoria paginii runda/preojixxx | Cod sursa (job #1088759) | Cod sursa (job #1766622) | Cod sursa (job #2804691) | Cod sursa (job #2348657)
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC
using namespace std;
int vector_de_tati[100001];
bool rez;
int compute_rad(int x)
{
int r;
if(vector_de_tati[x]==0)
return x;
vector_de_tati[x]=r=compute_rad(vector_de_tati[x]);
return r;
}
void disjoint(int c,int x,int y)
{
int r1=compute_rad(x);
int r2=compute_rad(y);
if(c==1)
{
vector_de_tati[r2]=r1;
return ;
}
if(r1==r2)
rez=true;
else
rez=false;
}
int main()
{
int n,q,c,x,y;
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&q);
while(q--)
{
scanf("%d%d%d",&c,&x,&y);
disjoint(c,x,y);
if(c==2)
if(rez==true)
printf("DA\n");
else
printf("NU\n");
}
return 0;
}